Skip to content

fix: stop passing inplace=True to deprecated pandas methods - #1137

Merged
has2k1 merged 3 commits into
has2k1:mainfrom
cristianchiriac:pandas-inplace-deprecation
Oct 29, 2026
Merged

has2k1 merged 3 commits into
has2k1:mainfrom
cristianchiriac:pandas-inplace-deprecation

Conversation

@cristianchiriac

Copy link
Copy Markdown
Contributor

The weekly tests against pandas main have been failing since pandas started deprecating inplace (PDEP-8), for example https://github.com/has2k1/plotnine/actions/runs/37121347599:

FAILED tests/test_guide_internals.py::test_no_after_scale_warning - pandas.errors.Pandas4Warning: The inplace keyword in DataFrame.reset_index is deprecated and will be removed in a future version (PDEP-8).
FAILED tests/test_utils.py::test_remove_missing - AssertionError: assert 4 == 1
FAILED tests/test_position.py::test_stack_non_linear_scale - assert 5 == 1
FAILED tests/test_ggsave.py::TestArguments::test_save_method - AssertionError: Issued an unexpected warning
...

With pandas 3.2.0.dev, inplace=True warns for DataFrame.reset_index, rename, eval, sort_values and drop. It does not warn for replace or fillna. This rewrites the 34 calls of the deprecated kind as assignments, e.g. data.reset_index(drop=True, inplace=True) → data = data.reset_index(drop=True). The one data.replace(..., inplace=True) in remove_missing is unchanged.

I checked every call site for code that relies on mutating the caller's frame. Where the frame is a parameter, it is either returned, or (in geom_linerange.draw_group and geom_path.draw_panel) only used locally after the call, so assigning the result is equivalent. There's also an entry under Bug Fixes in doc/changelog.qmd.

Test results (Windows, Python 3.12, pytest -n 6 tests):

main this branch
pandas 3.2.0.dev0+131 14 failed, 5935 warnings 8 failed, 42 warnings
pandas 3.0.6 8 failed 8 failed

The 8 remaining failures are the same on main and come from my environment: optional geom_smooth/geom_map dependencies not installed, the xkcd font, and a Windows PermissionError in test_last_plot_after_save. The image differences in the weekly job come from matplotlib main and aren't addressed here.

pandas 3.2 deprecates the inplace keyword of DataFrame.reset_index,
rename, eval, sort_values and drop (PDEP-8) with a Pandas4Warning, which
fails the weekly tests against pandas main. Assign the results instead.
DataFrame.replace keeps inplace=True, as it is not deprecated.
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.94%. Comparing base (986704a) to head (69840b7).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1137      +/-   ##
==========================================
+ Coverage   88.87%   88.94%   +0.07%     
==========================================
  Files         229      229              
  Lines       17290    17291       +1     
  Branches     2203     2203              
==========================================
+ Hits        15366    15379      +13     
+ Misses       1295     1286       -9     
+ Partials      629      626       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

cristianchiriac and others added 2 commits October 11, 2026 21:07
DataFrame.eval() is annotated as returning a broad union, which pyright
rejects when assigned back to a DataFrame.
The binaxis="y" branch of the shared binning sorts the data and the
bins before pairing them by index, so the reset_index results must be
kept. Check the counts per group and bin center with unsorted y values,
and that drop=True removes the empty bins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ce8Hr56xHurqiV5wEkVmxj
@has2k1
has2k1 merged commit afa9da1 into has2k1:main Oct 29, 2026
8 of 9 checks passed
@has2k1

has2k1 commented Oct 29, 2026

Copy link
Copy Markdown
Owner

@cristianchiriac, thank you.

jeroenjanssens added a commit to jeroenjanssens/plotnine that referenced this pull request Oct 29, 2026
The conflicts were where upstream changed code that this branch
converts to narwhals:

- The removal of the pandas inplace= calls (has2k1#1137) is superseded by
  the narwhals code.
- The modernized type annotations (has2k1#1140) are applied to the code of
  this branch too.
- The drawing context (has2k1#1143) uses copy-on-write for pandas<3 only if
  pandas has been imported.
- The fix of the kde nan check for numpy 2.5 (has2k1#1144) does not apply;
  the density is computed without statsmodels.

The new stat_bindot test reads the layer data with narwhals, so that
it works with the polars test backend.
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