Skip to content
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

Merged
merged 8 commits into from
Feb 12, 2023

Conversation

Zeddicus414
Copy link
Contributor

@@ -8,6 +8,26 @@ use crate::rules::pandas_vet::fixes::fix_inplace_argument;
use crate::violation::AlwaysAutofixableViolation;

define_violation!(
///## What it does
///Checks for `inplace=True` inside `pandas` code.
Copy link
Contributor

@not-my-profile not-my-profile Feb 12, 2023

Choose a reason for hiding this comment

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

nit: "pandas code" could be misunderstood to refer to the code of the pandas library.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this section should mention which methods are checked for this parameter.

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 think this section should mention which methods are checked for this parameter.

I'm not sure how to do this exactly. I think it's a bunch of methods.

Copy link
Contributor

@not-my-profile not-my-profile Feb 12, 2023

Choose a reason for hiding this comment

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

Ah ok ... in that case I think it's fine to just list a few of these methods as examples and say that there are more. Ideally the mentions of the example methods would be linked to their pandas documentation.

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 think I've addressed everything here except maybe for more detail about exactly which pandas methods this applies to and links to them maybe? I'm not sure how to do that in kind of a "principled" way, other than just linking to a few random pandas methods that happen to have this option.

If you are okay with it, I'm inclined to leave it as is and see if anyone else has a clear path to making it clearer. I think this is considerably better than no documentation.

Copy link
Contributor

@not-my-profile not-my-profile Feb 12, 2023

Choose a reason for hiding this comment

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

Fair enough linking several would indeed be quite random but I think linking just one as an example would be nice so that you can see how pandas documents the inplace parameter ... since the pandas documentation may change. How about the following?

Several methods from the pandas library accept an `inplace` parameter
(for example the [`pandas.DataFrame.replace`] method). This rule checks
for `inplace=True` in code using the `pandas` library.

// ... rest of documentation ...

[`pandas.DataFrame.replace`]: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.replace.html

Comment on lines 19 to 20
/// - It removes the ability to use the method chaining style for `pandas`
/// code.
Copy link
Contributor

Choose a reason for hiding this comment

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

I should have clarified ... I care in particular about the ruff rule output not being longer than 80 chars.

Since the /// is stripped from that the actual lines here can in fact be 88 chars long, so I think code. can be still on the previous line.

///
/// ## Why is this bad?
/// - `inplace=True` often does not provide a performance benefit. It is
/// likely to copy dataframes in the background.
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

/// 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
Copy link
Contributor

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.

@charliermarsh charliermarsh enabled auto-merge (squash) February 12, 2023 16:54
@charliermarsh charliermarsh added the documentation Improvements or additions to documentation label Feb 12, 2023
@charliermarsh charliermarsh merged commit 26f39ca into astral-sh:main Feb 12, 2023
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.

None yet

3 participants