Fix array-like pd.notna crash, normalize NumPy scalars, add update/delete input validation, export DataFrameOperations#145
Merged
saurabhrb merged 2 commits intousers/zhaodongwang/dataFrameExtensionClaudefrom Mar 17, 2026
Conversation
…e/delete IDs, add comprehensive tests Co-authored-by: saurabhrb <32964911+saurabhrb@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [PR #98] Address review comments and add tests for dataframe
Fix array-like pd.notna crash, normalize NumPy scalars, add update/delete input validation, export DataFrameOperations
Mar 17, 2026
4809dca
into
users/zhaodongwang/dataFrameExtensionClaude
1 check passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses four unresolved review comments from PR #98 against the
client.dataframenamespace: a crash on array-valued cells, silent NumPy serialization failures, missing ID validation inupdate()anddelete(), and missing exports/tests.utils/_pandas.pypd.notna()crash on array-like cells: Guard withpd.api.types.is_scalar(v)before callingpd.notna(); non-scalar values (lists, dicts, numpy arrays) pass through directly. Previously raisedValueError: The truth value of an array is ambiguous._normalize_scalar(v)helper convertsnp.integer→int,np.floating→float,np.bool_→bool,pd.Timestamp→ ISO string. DataFrames with integer columns producenp.int64by default, whichjson.dumps()cannot serialize.operations/dataframe.pyupdate()— validateid_columnvalues: After extracting IDs, raisesValueErrorlisting offending row indices if any value is not a non-empty string (catchesNaN,None, numeric IDs).update()— validate non-empty change columns: RaisesValueErrorif the DataFrame contains only theid_columnand no fields to update.delete()— validateidsSeries: ReturnsNoneimmediately for an empty Series; raisesValueErrorlisting offending indices for any non-string or blank value.operations/__init__.pyDataFrameOperationsso consumers can use it for type annotations.Tests
tests/unit/test_pandas_helpers.py— 11 isolated tests fordataframe_to_records()covering NaN handling, NumPy type normalization, Timestamp conversion, list/dict passthrough, and empty input.tests/unit/test_dataframe_operations.py— 35 tests covering the fullDataFrameOperationsnamespace, including all new validation paths.Original prompt
Context
This PR addresses unresolved review comments from PR #98 ("add dataframe methods") and adds comprehensive test coverage for the DataFrame operations namespace (
client.dataframe).The base branch is
users/zhaodongwang/dataFrameExtensionClaudewhich contains the current state of the DataFrame operations code from PR #98.Files to modify
1.
src/PowerPlatform/Dataverse/utils/_pandas.pyCurrent code at the HEAD of the PR branch (
8838bb69533dd8830bac8724c44696771a6704e7):Required changes:
Fix A:
pd.notna()crash on array-like values (unresolved comment #98 (comment))pd.notna(v)raisesValueError: The truth value of an array is ambiguouswhen a cell contains a list, dict, numpy array, etc. Fix by guarding withpd.api.types.is_scalar(v):Fix B: NumPy scalar types not normalized (acknowledged but deferred by author in #98 (comment))
NumPy scalars (
np.int64,np.float64,np.bool_) are NOT JSON-serializable by defaultjson.dumps(). DataFrames with integer columns producenp.int64values. Add a helper function_normalize_scalar(v)that:pd.Timestampto.isoformat()numpy.integertypes to Pythonintnumpy.floatingtypes to Pythonfloatnumpy.bool_to PythonboolUse
import numpy as npandisinstancechecks.2.
src/PowerPlatform/Dataverse/operations/dataframe.pyCurrent code at the HEAD of the PR branch:
Required changes:
Fix C: Validate
id_columnvalues in...This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.