Skip to content

Commit 6957488

Browse files
author
Saurabh Badenkal
committed
Raise ValueError on empty DataFrame in update(), add test
1 parent a61472b commit 6957488

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/PowerPlatform/Dataverse/operations/dataframe.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ def update(
242242
"""
243243
if not isinstance(changes, pd.DataFrame):
244244
raise TypeError("changes must be a pandas DataFrame")
245+
if changes.empty:
246+
raise ValueError("changes must be a non-empty DataFrame")
245247
if id_column not in changes.columns:
246248
raise ValueError(f"id_column '{id_column}' not found in DataFrame columns")
247249

tests/unit/test_dataframe_operations.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ def test_update_empty_change_columns(self):
290290
self.client.dataframe.update("account", df, id_column="accountid")
291291
self.assertIn("No columns to update", str(ctx.exception))
292292

293+
def test_update_empty_dataframe_raises(self):
294+
"""Empty DataFrame raises ValueError without calling the API."""
295+
df = pd.DataFrame(columns=["accountid", "name"])
296+
with self.assertRaises(ValueError) as ctx:
297+
self.client.dataframe.update("account", df, id_column="accountid")
298+
self.assertIn("non-empty", str(ctx.exception))
299+
self.client._odata._update.assert_not_called()
300+
293301
def test_update_clear_nulls_false(self):
294302
"""NaN values are omitted from the update payload when clear_nulls=False."""
295303
df = pd.DataFrame([{"accountid": "guid-1", "name": "New Name", "telephone1": None}])

0 commit comments

Comments
 (0)