-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PD002 use-of-inplace-argument documentation #2799
Changes from 6 commits
be4a817
e5721c9
a170efa
bd4924b
4ef66a2
03e32f0
bb65f53
e98e39e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,29 @@ use crate::rules::pandas_vet::fixes::fix_inplace_argument; | |
use crate::violation::AlwaysAutofixableViolation; | ||
|
||
define_violation!( | ||
/// ## What it does | ||
/// Checks for `inplace=True` in code using the `pandas` library. | ||
/// | ||
/// ## Why is this bad? | ||
/// - `inplace=True` often does not provide a performance benefit. It is | ||
/// likely to copy dataframes in the background. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Markdown lists look a bit better if the wrapped text is indented as much as the first line of the list item. |
||
/// - It encourages mutation rather than immutable data, which is harder to | ||
/// reason about and may cause bugs. | ||
/// - It removes the ability to use the method chaining style for `pandas` | ||
/// code. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should have clarified ... I care in particular about the Since the |
||
/// | ||
/// ## 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) | ||
pub struct UseOfInplaceArgument; | ||
); | ||
impl AlwaysAutofixableViolation for UseOfInplaceArgument { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# use-of-inplace-argument (PD002) | ||
|
||
Derived from the **pandas-vet** linter. | ||
|
||
Autofix is always available. | ||
|
||
## What it does | ||
Checks for `inplace=True` in code using the `pandas` library. | ||
|
||
## Why is this bad? | ||
- `inplace=True` often does not provide a performance benefit. It is | ||
likely to copy dataframes in the background. | ||
- It encourages mutation rather than immutable data, which is harder to | ||
reason about and may cause bugs. | ||
- It removes the ability to use the method chaining style for `pandas` | ||
code. | ||
|
||
## 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: In the other rule documentations we have been using
*
as a list marker rather than-
... it would be nice to be consistent.