Add PD002 use-of-inplace-argument documentation (#2799)

This commit is contained in:
Zeddicus414 2023-02-12 12:10:34 -06:00 committed by GitHub
parent 02897a141b
commit 26f39cac2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 2 deletions

View 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)