Skip to content

Fix generate_figures crashing with polars 2 - #224

Closed
CodyCBakerPhD wants to merge 3 commits into
mainfrom
claude/fix-generate-figures-polars-2
Closed

CodyCBakerPhD wants to merge 3 commits into
mainfrom
claude/fix-generate-figures-polars-2

Conversation

@CodyCBakerPhD

@CodyCBakerPhD CodyCBakerPhD commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #221. On a fresh install, nwb_benchmarks generate_figures crashes partway through:

File ".../database/_processing.py", line 325, in _preprocess_environments
    .replace({v: k for k, v in ENVIRONMENT_TIMEPOINTS.items()}, default=None)
polars.exceptions.ArgumentRemovedError: the argument 'default' for 'Expr.replace' was deprecated in version 1.0.0 and has been removed in version 2.0. Use `replace_strict` instead to set a default while replacing values.

#227 has since pinned polars<2 in the database group to avoid the crash. This PR fixes the call itself, so the code also works under polars 2. With this merged, the pin is no longer needed for this call. This PR leaves the pin and its comment in pyproject.toml as they are.

Change

  • _preprocess_environments uses Expr.replace_strict(mapping, default=None). It does the same mapping: environments without a timepoint become null. It has existed since polars 1.0, so it works on both 1.x and 2.x.
  • New tests/test_environment_timepoints.py checks that a known environment ID gets its timepoint and an unknown one gets null. Under polars 2 it fails with the error above on the old line and passes with the fix.
  • Package version 0.4.3 → 0.4.4 (patch), since Pinned polars below 2 for the database group #227 already released 0.4.3. DATABASE_VERSION is unchanged.

Testing


Generated by Claude Code

`nwb_benchmarks generate_figures` stopped partway through with
`ArgumentRemovedError` when polars 2 is installed: the environment
preprocessing labels each environment with its timepoint through
`Expr.replace(mapping, default=None)`, and polars 2.0 removed the
`default` argument of `replace`. polars is unpinned, so a fresh install
gets 2.x. The figures that #221 added are written before that point, but
the run then crashes in `plot_performance_across_versions`.

`Expr.replace_strict(mapping, default=None)` does the same mapping
(environments without a timepoint become null) and exists since
polars 1.0, so this works with both 1.x and 2.x.

Adds a test for the timepoint labeling, which fails with the old call
under polars 2. Package version 0.4.2 -> 0.4.3 (patch).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019XGZPsK77kY9cukQuY4a7R
@CodyCBakerPhD CodyCBakerPhD self-assigned this Nov 9, 2026
@CodyCBakerPhD

Copy link
Copy Markdown
Collaborator Author

with #227 do we actually need this?

#227 released 0.4.3 on main, so after merging main this branch carried
the same version and the version check failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019XGZPsK77kY9cukQuY4a7R

Copy link
Copy Markdown
Collaborator Author

Not for now. With #227, anyone who installs the database group gets polars 1.x, and generate_figures works.

This PR only matters in two cases:

  • polars 2 from another source: a dependency group isn't part of the package's published dependencies, so the pin only applies when the group itself is installed. An environment that gets polars some other way can still end up on 2.x and crash.
  • Lifting the pin later: when you want polars 2 (new features, or once 1.x stops getting updates or wheels for new Python versions), this is the one call that blocks it today. I only ran the figure code on polars 2.1, not the whole package.

So either close this and keep the pin, or merge it and drop the pin in the same PR. I'd lean towards the second, but it's your call.


Generated by Claude Code


Generated by Claude Code

@CodyCBakerPhD
CodyCBakerPhD deleted the claude/fix-generate-figures-polars-2 branch November 12, 2026 23:55
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.

2 participants