Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copy-on-write chained assignment for default assignment #1508

Conversation

johnchristopherjones
Copy link

@johnchristopherjones johnchristopherjones commented Feb 21, 2024

With Copy-On-Write enabled with at least Pandas 2.2.0, Pandera emits ChainedAssignmentError warnings whenever setting defaults:

[…]/.venv/lib/python3.11/site-packages/pandera/backends/pandas/array.py:337: ChainedAssignmentError: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method.
When using the Copy-on-Write mode, such inplace method never works to update the original DataFrame or Series, because the intermediate object on which we are setting values always behaves as a copy.

For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' instead, to perform the operation inplace on the original object.


  check_obj[schema.name].fillna(schema.default, inplace=True)

This PR just changes the offending line to use the suggested syntax.

@johnchristopherjones
Copy link
Author

Resolved by #1464

@johnchristopherjones johnchristopherjones deleted the bugfix/copy-on-write-warning branch February 21, 2024 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant