mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Add PD002 use-of-inplace-argument documentation (#2799)
This commit is contained in:
parent
02897a141b
commit
26f39cac2f
3 changed files with 56 additions and 2 deletions
30
docs/rules/use-of-inplace-argument.md
Normal file
30
docs/rules/use-of-inplace-argument.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
# use-of-inplace-argument (PD002)
|
||||
|
||||
Derived from the **pandas-vet** linter.
|
||||
|
||||
Autofix is always available.
|
||||
|
||||
## What it does
|
||||
Checks for `inplace=True` usages in `pandas` function and method
|
||||
calls.
|
||||
|
||||
## Why is this bad?
|
||||
Using `inplace=True` encourages mutation rather than immutable data,
|
||||
which is harder to reason about and may cause bugs. It also removes the
|
||||
ability to use the method chaining style for `pandas` operations.
|
||||
|
||||
Further, in many cases, `inplace=True` does not provide a performance
|
||||
benefit, as `pandas` will often copy `DataFrames` in the background.
|
||||
|
||||
## Example
|
||||
```python
|
||||
df.sort_values("col1", inplace=True)
|
||||
```
|
||||
|
||||
Use instead:
|
||||
```python
|
||||
sorted_df = df.sort_values("col1")
|
||||
```
|
||||
|
||||
## References
|
||||
- [Why You Should Probably Never Use pandas inplace=True](https://towardsdatascience.com/why-you-should-probably-never-use-pandas-inplace-true-9f9f211849e4)
|
Loading…
Add table
Add a link
Reference in a new issue