Skip to content

Comments

[pandas-vet] Make example error out-of-the-box (PD002)#22561

Merged
amyreese merged 1 commit intoastral-sh:mainfrom
MeGaGiGaGon:patch-1
Jan 20, 2026
Merged

[pandas-vet] Make example error out-of-the-box (PD002)#22561
amyreese merged 1 commit intoastral-sh:mainfrom
MeGaGiGaGon:patch-1

Conversation

@MeGaGiGaGon
Copy link
Contributor

Summary

Part of #18972

This PR makes pandas-use-of-inplace-argument (PD002)'s example error out-of-the-box.

Old example

df.sort_values("col1", inplace=True)

New example

import pandas as pd

students_df = pd.read_csv("students.csv")
students_df.sort_values("name", inplace=True)

The "Use instead" section was also updated to emphasize the benefits gained from being able to use the method chaining style.

import pandas as pd

students = pd.read_csv("students.csv").sort_values("name")

Test Plan

N/A, no functionality/tests affected

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 13, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Comment on lines +29 to +30
/// students = pd.read_csv("students.csv")
/// students.sort_values("name", inplace=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer names that are more generic

Suggested change
/// students = pd.read_csv("students.csv")
/// students.sort_values("name", inplace=True)
/// data = pd.read_csv("data.csv")
/// data.sort_values("column", inplace=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to leave the name since that matches how some of the other examples in pandas-vet are:
https://docs.astral.sh/ruff/rules/pandas-use-of-dot-is-null/

import pandas as pd

animals_df = pd.read_csv("animals.csv")
pd.isnull(animals_df)

https://docs.astral.sh/ruff/rules/pandas-use-of-dot-ix/ (The one I copied from)

import pandas as pd

students_df = pd.read_csv("students.csv")
students_df.ix[0]  # 0th row or row with label 0?

@MichaReiser MichaReiser added the documentation Improvements or additions to documentation label Jan 14, 2026
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! These names seem okay to me, if it's alright with @amyreese.

@amyreese amyreese merged commit 745dfa6 into astral-sh:main Jan 20, 2026
42 checks passed
@MeGaGiGaGon MeGaGiGaGon deleted the patch-1 branch January 20, 2026 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants