Fix pandas SettingWithCopyWarning in nested column access#384
Fix pandas SettingWithCopyWarning in nested column access#384
Conversation
Co-authored-by: gitosaurus <6794831+gitosaurus@users.noreply.github.com>
|
@copilot It's good that the warning is gone, but if the upstream code is trying to set a value, your fix looks like it will simply cause the set-attempt to be a no-op. The warnings suggested this pattern for an intentional write-to-slice: Where in the call stack was the original warning triggered? That may be where it needs to change. |
The warning was triggered in the call stack at The fix is at the right place. In The modification at line 279 is not a no-op - it's adding columns to the new result dataframe that will be returned to the caller. The Commit: 2b374e4 |
Description
This PR addresses deprecation warnings that appear when running the test suite, specifically fixing a
SettingWithCopyWarningthat could occur when accessing nested columns via list notation.Changes
SettingWithCopyWarning Fix
Modified the
_getitem_listmethod insrc/nested_pandas/nestedframe/core.pyto ensure operations are performed on a copy rather than a potential view:When accessing multiple columns including nested ones (e.g.,
nf[['a', 'b', 'nested.c']]), the code subsequently sets nested columns on the result object. Without the explicit.copy(), this could triggerSettingWithCopyWarningin certain pandas versions when the initial selection returns a view rather than a copy.NumPy 2.0 Compatibility
Verified that the
__array__method inNestedExtensionArrayalready has the correct signature for NumPy 2.0 compatibility:No changes were needed as the implementation already properly handles the
copyparameter as specified in the NumPy 2.0 migration guide.Testing
test_get_nested_columnstest___array__Related Issues
Fixes deprecation warnings reported in the issue where pandas and numpy deprecation warnings appeared during test execution.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
epyc.astro.washington.edu/usr/bin/python3 /home/REDACTED/.local/bin/pytest tests/ -W default::DeprecationWarning -W default::FutureWarning(dns block)/usr/bin/python3 /home/REDACTED/.local/bin/pytest tests/nested_pandas/ -x -v(dns block)nasa-irsa-euclid-q1.s3.us-east-1.amazonaws.com/usr/bin/python3 /home/REDACTED/.local/bin/pytest tests/ -W default::DeprecationWarning -W default::FutureWarning(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.