-
Notifications
You must be signed in to change notification settings - Fork 88
Fix pandas FutureWarning: Avoid chained assignment with copy() in icephys.py #2129
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
base: dev
Are you sure you want to change the base?
Conversation
@rly 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
@copilot This fix may ultimately require a PR in the HDMF repository instead of PyNWB. |
… in icephys.py Co-authored-by: rly <310197+rly@users.noreply.github.com>
@copilot please review and address the failing tests |
You're correct. After investigating, the issue occurs in PyNWB's
I've identified and fixed the issue causing the test failures. The problem was that my initial 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:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: rly <310197+rly@users.noreply.github.com>
Co-authored-by: rly <310197+rly@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #2129 +/- ##
=======================================
Coverage 95.19% 95.19%
=======================================
Files 28 28
Lines 2849 2852 +3
Branches 736 736
=======================================
+ Hits 2712 2715 +3
Misses 83 83
Partials 54 54
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This PR fixes pandas FutureWarning messages that appear when running PyNWB tests with Python 3.14. The warnings indicate that chained assignment patterns will not work in pandas 3.0 with Copy-on-Write enabled.
Problem
When running tests with Python 3.14.0rc2+, the following warnings were raised:
The warnings occurred in
src/pynwb/icephys.py
at lines 749, 751, and 756 in theIntracellularRecordingsTable.to_dataframe()
method.Solution
The issue was resolved by copying DataFrame columns before performing transformations, which avoids the chained assignment pattern that triggers pandas warnings:
Before:
After:
This approach was chosen over the initially attempted
.loc
syntax because:('electrodes', 'electrode')
.loc[:, ('column', 'name')] = [...]
caused aValueError: Must have equal len keys and value when setting with an ndarray
.copy()
approach maintains identical functionality while avoiding chained assignmentChanges
electrode_col = res[('electrodes', 'electrode')].copy()
before assignmentstimulus_col = res[('stimuli', 'stimulus')].copy()
before assignmentresponse_col = res[('responses', 'response')].copy()
before assignmentThe fix is minimal and preserves all existing functionality while ensuring compatibility with future pandas versions.
Fixes #2126.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.