Commit 8a6ef8c
Add client.dataframe namespace for pandas DataFrame CRUD operations (#98)
## Summary
Adds a `client.dataframe` namespace with pandas DataFrame/Series
wrappers for all CRUD operations, plus two advanced example scripts, and
a minor SDK enhancement for table metadata. Users can now query, create,
update, and delete Dataverse records using DataFrame-native inputs and
outputs -- no manual dict conversion required.
## Quick Example
```python
import pandas as pd
from azure.identity import InteractiveBrowserCredential
from PowerPlatform.Dataverse.client import DataverseClient
credential = InteractiveBrowserCredential()
with DataverseClient("https://yourorg.crm.dynamics.com", credential) as client:
# Query records as a DataFrame (all pages consolidated automatically)
df = client.dataframe.get("account", select=["name", "telephone1"], top=5)
# Create records from a DataFrame (returns Series of GUIDs)
new_records = pd.DataFrame([
{"name": "Acme Corp", "telephone1": "555-9000"},
{"name": "Globex Inc", "telephone1": "555-9001"},
])
new_records["accountid"] = client.dataframe.create("account", new_records)
# Update records (NaN/None skipped by default; use clear_nulls=True to clear fields)
new_records["telephone1"] = ["555-1111", "555-2222"]
client.dataframe.update("account", new_records[["accountid", "telephone1"]], id_column="accountid")
# Delete records
client.dataframe.delete("account", new_records["accountid"])
```
## Changes
### DataFrame CRUD (`client.dataframe` namespace)
| File | Description |
|------|-------------|
| `src/.../operations/dataframe.py` | `DataFrameOperations` class:
`get()`, `create()`, `update()`, `delete()` |
| `src/.../utils/_pandas.py` | `dataframe_to_records()` helper --
normalizes NumPy, datetime, NaN/None |
| `client.py` | Added `self.dataframe = DataFrameOperations(self)` |
| `pyproject.toml` | Added `pandas>=2.0.0` required dependency |
| `README.md` | DataFrame usage examples |
| `operations/__init__.py` | Cleanup (`__all__ = []`) |
### SDK Enhancement: TableInfo primary column metadata (fixes #148)
| File | Description |
|------|-------------|
| `src/.../data/_odata.py` | `_get_entity_by_table_schema_name()` and
`_get_table_info()` now select `PrimaryNameAttribute` and
`PrimaryIdAttribute` from EntityDefinitions |
| `src/.../models/table_info.py` | `TableInfo` includes
`primary_name_attribute` and `primary_id_attribute` fields |
| `tests/unit/models/test_table_info.py` | Tests for new fields in
`from_dict`, `from_api_response`, and legacy key access |
### Advanced Examples
| File | Description |
|------|-------------|
| `examples/advanced/dataframe_operations.py` | DataFrame CRUD
walkthrough |
| `examples/advanced/prodev_quick_start.py` | Pro-dev: 4-table system
with relationships, DataFrame CRUD, query/analyze. Uses
`result.primary_name_attribute` from `tables.create()` |
| `examples/advanced/datascience_risk_assessment.py` | Data science:
5-step risk pipeline with 3 LLM provider options (Azure AI Inference,
OpenAI, GitHub Copilot SDK), matplotlib charts |
### Test Files
| File | Tests |
|------|-------|
| `test_dataframe_operations.py` | 44 |
| `test_client_dataframe.py` | 26 |
| `test_pandas_helpers.py` | 33 |
| `test_table_info.py` | +1 (primary fields) |
## API Design
| Method | Input | Output | Underlying API |
|--------|-------|--------|----------------|
| `get(table, ...)` | OData params | `pd.DataFrame` | `records.get()` |
| `get(table, record_id=...)` | GUID | 1-row `pd.DataFrame` |
`records.get()` |
| `create(table, df)` | `pd.DataFrame` | `pd.Series` of GUIDs |
`CreateMultiple` |
| `update(table, df, id_column)` | `pd.DataFrame` | `None` |
`UpdateMultiple` |
| `delete(table, ids)` | `pd.Series` | `Optional[str]` | `BulkDelete` |
### Design Decisions
- **`clear_nulls`**: Default `False` skips NaN (field unchanged). `True`
sends null to clear.
- **Type normalization**: np.int64/float64/bool_/ndarray,
datetime/date/np.datetime64, pd.Timestamp -- all auto-converted.
- **ID validation**: Strip whitespace, report DataFrame index labels in
errors.
- **pandas required**: Core dependency by team decision.
## Test Results
```
396 passed, 8 warnings (pre-existing deprecation), 4 subtests passed
```
| Check | Result |
|-------|--------|
| Full test suite | 396 pass, 0 fail |
| mypy | 0 errors |
| black / isort | Clean |
| E2E prodev | PASS (4 tables, 3 relationships, 13 records, full CRUD
cycle) |
| E2E datascience | PASS (7 accounts, 3 cases, 8 opportunities, risk
scoring, charts) |
| PR review threads | 54/54 resolved |
## Issues Addressed
- Fixes #148: `tables.create()` now exposes `primary_name_attribute` via
Dataverse metadata
- Followup #147: `QueryBuilder.to_dataframe()` tracked for future work
---------
Co-authored-by: Saurabh Badenkal <sbadenkal@microsoft.com>1 parent c357eff commit 8a6ef8c
File tree
18 files changed
+3205
-6
lines changed- .claude/skills/dataverse-sdk-use
- examples/advanced
- src/PowerPlatform/Dataverse
- claude_skill/dataverse-sdk-use
- data
- models
- operations
- utils
- tests/unit
- models
18 files changed
+3205
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
132 | | - | |
| 135 | + | |
133 | 136 | | |
134 | 137 | | |
135 | 138 | | |
| |||
171 | 174 | | |
172 | 175 | | |
173 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
174 | 213 | | |
175 | 214 | | |
176 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
232 | 234 | | |
233 | 235 | | |
234 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
235 | 273 | | |
236 | 274 | | |
237 | 275 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
0 commit comments