Skip to content

Pandas 3.1: The inplace keyword in DataFrame.drop is deprecated - #12447

Merged
crusaderky merged 1 commit into
dask:mainfrom
crusaderky:pandas31-drop
Jun 10, 2026
Merged

crusaderky merged 1 commit into
dask:mainfrom
crusaderky:pandas31-drop

Conversation

@crusaderky

@crusaderky crusaderky commented Jun 5, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #12444

I can't replicate the need for the original hack.
It looks like drop() is always deep, hack or not, with pandas 2.x and always shallow in pandas 3. Maybe it's a legacy of pandas 1.x?

poc.py

import pandas as pd
import numpy as np


def get_np(df):
    arr = df._mgr.blocks[0].values[0]
    while arr.base is not None:
        arr = arr.base
    return arr

def is_shallow(a, b, n):
    np_a = get_np(a)
    np_b = get_np(b)
    np_a[0, 0] = n
    return np_b[0, 0] == n

print(pd.__version__)
a = pd.DataFrame({"x": np.arange(100, dtype=np.int32), "y": np.arange(100, dtype=np.float64)})

b = a.drop(columns="y")
print("DataFrame.drop() is shallow:", is_shallow(a, b, 123))

c = a.copy(deep=False)
c.drop(columns=["y"], inplace=True)
print("drop_by_shallow_copy() is shallow:", is_shallow(a, c, 456))
print("---")
$ for e in mindeps-dataframe py310 py311 py312 py313 nightly; do pixi r -e $e python poc.py; done
2.0.3
DataFrame.drop() is shallow: False
drop_by_shallow_copy() is shallow: False
---
2.1.4
DataFrame.drop() is shallow: False
drop_by_shallow_copy() is shallow: False
---
2.2.3
DataFrame.drop() is shallow: False
drop_by_shallow_copy() is shallow: False
---
2.3.3
DataFrame.drop() is shallow: False
drop_by_shallow_copy() is shallow: False
---
3.0.3
DataFrame.drop() is shallow: True
drop_by_shallow_copy() is shallow: True
---
3.1.0.dev0+1006.g7ecdde9b8e
DataFrame.drop() is shallow: True
/home/crusaderky/github/dask/poc.py:24: Pandas4Warning: The inplace keyword in DataFrame.drop is deprecated and will be removed in a future version. See PDEP-8 for more details:https://pandas.pydata.org/pdeps/0008-inplace-methods-in-pandas.html
  c.drop(columns=["y"], inplace=True)
drop_by_shallow_copy() is shallow: True
---

@crusaderky

Copy link
Copy Markdown
Collaborator Author

@rjzamora you're the original author (#5664, #5675). Any idea why it looks always deep on Pandas 2.0~2.3?

@github-actions

github-actions Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

     25 files  ±0       25 suites  ±0   6h 47m 58s ⏱️ - 8m 57s
 18 643 tests ±0   17 454 ✅ ±0   1 189 💤 ±0  0 ❌ ±0 
379 089 runs  ±0  331 839 ✅  - 4  47 250 💤 +4  0 ❌ ±0 

Results for commit d5de55a. ± Comparison against base commit 2be4507.

♻️ This comment has been updated with latest results.

@rjzamora

rjzamora commented Jun 5, 2026

Copy link
Copy Markdown
Member

you're the original author (#5664, #5675). Any idea why it looks always deep on Pandas 2.0~2.3?

The original change predated Pandas copy-on-write changes by a long time. cc @TomAugspurger @mroeschke in case they have any quick notes :)

@crusaderky

Copy link
Copy Markdown
Collaborator Author

@TomAugspurger @mroeschke gentle ping

@crusaderky
crusaderky merged commit c437b7a into dask:main Jun 10, 2026
33 checks passed
@crusaderky
crusaderky deleted the pandas31-drop branch June 10, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pandas4Warning: The inplace keyword in DataFrame.drop is deprecated

3 participants