Skip to content

fix: address pandas chained-assignment FutureWarning ahead of pandas 3.0#39

Open
tabedzki wants to merge 3 commits into
devfrom
tabedzki/fix/addressing-pandas-chained-assignment
Open

fix: address pandas chained-assignment FutureWarning ahead of pandas 3.0#39
tabedzki wants to merge 3 commits into
devfrom
tabedzki/fix/addressing-pandas-chained-assignment

Conversation

@tabedzki

@tabedzki tabedzki commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

What

Silences the pandas 2.3 ChainedAssignmentError FutureWarning in two DataFrame-transform spots so the code is ready for the pandas 3.0 copy-on-write default.

  • pixelmap/utils/survey.py (parse_survey_file): replace the per-column loop assignment on a sliced-then-copied DataFrame with a single assign().astype().
  • pixelmap/backend.py (format_wiring_df): replace the two consecutive df[column] = ... assignments per loop iteration with object-dtype Series applied in a single assign().

Why

Under pandas 2.3 these assignments emit:

FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!

The warning is a refcount-sensitive false positive — the assignments aren't truly chained — but it fires in the real call path (not in isolation), and the underlying single-step-assignment guidance is the correct forward-compatible form. Both rewrites set column values in one step, which is warning-free now and correct under pandas 3.0 copy-on-write.

Behaviour is unchanged: parse_survey_file still raises ValueError on unparseable data, and format_wiring_df still returns the same (shank_id, electrode_id) tuple cells.

Verification

  • All 3 real survey fixtures (1.0, 2.0-1shank, 2.0-4shanks) parse with correct dtypes and zero FutureWarnings under -W error::FutureWarning.
  • Full suite passes with FutureWarning promoted to error: 120 passed.
  • Codebase swept for other pandas 3.0 breakers (inplace=, chained df[..][..]=, .applymap, .iteritems, .append on DataFrames, .ix, etc.) — these two were the only affected spots.

tabedzki added 3 commits July 8, 2026 10:40
…urvey_file

Replace per-column loop assignment on a sliced-then-copied DataFrame with a
single assign().astype() so column dtypes are set in one step. This silences
the pandas 2.3 ChainedAssignmentError FutureWarning (a refcount-sensitive
false positive that fires in the real call path) ahead of the pandas 3.0
copy-on-write default, while preserving the ValueError-on-bad-data contract.

Assisted-by: ClaudeCode:claude-opus-4.8
…_wiring_df

The two consecutive df[column] = ... assignments per loop iteration triggered
the pandas 2.3 ChainedAssignmentError FutureWarning in the real call path
(the elevated DataFrame refcount that the warning keys on is only present when
called through the app, not in isolation). Build each tuple column as an
object-dtype Series and apply them in a single assign(), which sets the values
in one step ahead of the pandas 3.0 copy-on-write default.

Assisted-by: ClaudeCode:claude-opus-4.8
Run uv sync --upgrade to refresh the lockfile (pandas 2.3.1 -> 3.0.3 on
Python >=3.11, panel 1.7.5 -> 1.9.3, numpy -> 2.5.1, and ~48 others). Raise
the pandas constraint from >=2.0.0 to >=2.3 so the resolved version is one
where the chained-assignment behaviour matches the copy-on-write fixes in
this branch. Keep requires-python >=3.10: pandas 3.0 dropped 3.10, so the
lock resolves pandas 2.3.x for py<3.11 and 3.0.x for py>=3.11 via markers.

Full test suite passes on pandas 3.0.3, including with FutureWarning
promoted to error.

Assisted-by: ClaudeCode:claude-opus-4.8
@tabedzki tabedzki marked this pull request as ready for review July 8, 2026 14:59
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