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

DOC: fix PR02 errors in docstrings - pandas.core.groupby.SeriesGroupBy.idxmax, pandas.core.groupby.SeriesGroupBy.idxmin #57145

Merged
merged 8 commits into from
Feb 1, 2024

Conversation

jordan-d-murphy
Copy link
Contributor

All PR02 Errors resolved in the following cases:

  1. scripts/validate_docstrings.py --format=actions --errors=PR02 pandas.core.groupby.SeriesGroupBy.idxmax
  2. scripts/validate_docstrings.py --format=actions --errors=PR02 pandas.core.groupby.SeriesGroupBy.idxmin

OUTPUT:

  1. scripts/validate_docstrings.py --format=actions --errors=PR02 pandas.core.groupby.SeriesGroupBy.idxmax
################################################################################
################################## Validation ##################################
################################################################################

Docstring for "pandas.core.groupby.SeriesGroupBy.idxmax" correct. :)
  1. scripts/validate_docstrings.py --format=actions --errors=PR02 pandas.core.groupby.SeriesGroupBy.idxmin
################################################################################
################################## Validation ##################################
################################################################################

Docstring for "pandas.core.groupby.SeriesGroupBy.idxmin" correct. :)

…y.idxmax, pandas.core.groupby.SeriesGroupBy.idxmin
@mroeschke mroeschke added the Docs label Jan 30, 2024
@datapythonista
Copy link
Member

What's the reason to stop reusing the docstring here? Seems like the parameters are the same, no?

@jordan-d-murphy
Copy link
Contributor Author

jordan-d-murphy commented Jan 31, 2024

@datapythonista the reason I removed @doc(Series.idxmin.__doc__) and @doc(Series.idxmax.__doc__) is that Series.idxmin and Series.idxmax have extra parameters *args and **kwargs that were causing the PR02 errors when the same docstring was used for SeriesGroupBy.idxmin and SeriesGroupBy.idxmax (as these do not use *args and **kwargs).

I am open to other suggestions for resolving the PR02 errors if you know of other ways I can resolve this.

@jordan-d-murphy
Copy link
Contributor Author

@mroeschke can you take a look at the examples I added?

@datapythonista
Copy link
Member

the reason I removed @doc(Series.idxmin.__doc__) and @doc(Series.idxmax.__doc__) is that Series.idxmin and Series.idxmax have extra parameters *args and **kwargs

I see. Sorry, I compared the one changed here with the one in DataFrame and they have the same signature. I see it's the one with Series that has a different signature.

The way we've been dealing with this is using variables for the parts that change. In this case you could create a new variable extra_args which is empty in one case, and contains the docstring part of *args and **kwargs when needed. It's difficult to tell at what point reusing docstrings make things easier or more difficult, but for this case it may make sense if we are already reusing the docstrings.

@mroeschke
Copy link
Member

IMO I am generally in favor of moving away from dynamic docstring. Especially since docstrings are a good avenue for new contributions, I think the overhead of doc/Appender/Substitution can make fixing docstrings more onerous. Also templating can get in the way of automatic docstring formatting that ruff now provides: #56863

@rhshadrach
Copy link
Member

IMO I am generally in favor of moving away from dynamic docstring

+1

@rhshadrach
Copy link
Member

It's difficult to tell at what point reusing docstrings make things easier or more difficult, but for this case it may make sense if we are already reusing the docstrings.

You would also have to do something about the different examples, as now the groupby version has groupby-specific examples.

@jordan-d-murphy
Copy link
Contributor Author

jordan-d-murphy commented Feb 1, 2024

@datapythonista considering the input above, is the effort to refactor this (main docstring + additional args + examples) worth undertaking at this time, or do we want to revisit that in a separate conversation outside of the scope of this PR?

There are other similar PR02 errors that could be resolved with either approach.

@datapythonista
Copy link
Member

I was just pointing out at how we've been doing things so far. And as I said, I really don't know when reusing docstrings simplify things, and when it makes them more complex, it's probably more a personal preference than something we can agree with, and I don't have a strong opinion. So, I'm surely happy to let you decide how to move forward here.

@rhshadrach
Copy link
Member

@jordan-d-murphy - when you merge main, you can remove any references to axis in your docstring as this argument has been removed.

@jordan-d-murphy
Copy link
Contributor Author

Thank you all so much for the guidance and feedback. For now, I'll refrain from refactoring the docstring into the dynamic approach. I've merged main back into this branch to resolve conflicts, and the pipeline is running again. I also removed the axis references. Can someone take another look once the pipeline finishes and the checks are green?

@jordan-d-murphy
Copy link
Contributor Author

@rhshadrach in this PR I've removed axis for SeriesGroupBy.idxmin and SeriesGroupBy.idxmax

I see Series.idxmin and Series.idxmax also have references to axis, should I remove those as well? I can update this PR with that change or open a separate PR for that fix if it's needed.

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

I see Series.idxmin and Series.idxmax also have references to axis, should I remove those as well? I can update this PR with that change or open a separate PR for that fix if it's needed.

The axis argument in these methods will remain; the argument was only removed in the groupby variant.

pandas/core/groupby/generic.py Outdated Show resolved Hide resolved
pandas/core/groupby/generic.py Outdated Show resolved Hide resolved
@jordan-d-murphy
Copy link
Contributor Author

@rhshadrach can you give another look at this when you get time? I've addressed the changes you requested

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

lgtm

@rhshadrach rhshadrach merged commit d9f9e12 into pandas-dev:main Feb 1, 2024
50 checks passed
@rhshadrach
Copy link
Member

Thanks @jordan-d-murphy!

@rhshadrach rhshadrach added this to the 3.0 milestone Feb 1, 2024
@jordan-d-murphy jordan-d-murphy deleted the issue#57111_2 branch February 1, 2024 21:52
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants