Repository navigation
fix: stop passing inplace=True to deprecated pandas methods - #1137
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The weekly tests against pandas
mainhave been failing since pandas started deprecatinginplace(PDEP-8), for example https://github.com/has2k1/plotnine/actions/runs/37121347599:With pandas 3.2.0.dev,
inplace=Truewarns forDataFrame.reset_index,rename,eval,sort_valuesanddrop. It does not warn forreplaceorfillna. 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 onedata.replace(..., inplace=True)inremove_missingis 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_groupandgeom_path.draw_panel) only used locally after the call, so assigning the result is equivalent. There's also an entry under Bug Fixes indoc/changelog.qmd.Test results (Windows, Python 3.12,
pytest -n 6 tests):mainThe 8 remaining failures are the same on
mainand come from my environment: optionalgeom_smooth/geom_mapdependencies not installed, the xkcd font, and a WindowsPermissionErrorintest_last_plot_after_save. The image differences in the weekly job come from matplotlibmainand aren't addressed here.