-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update the pd.Index.asof docstring #20344
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: update the pd.Index.asof docstring #20344
Conversation
pandas/core/indexes/base.py
Outdated
Return the latest index label up to and including the passed label. | ||
|
||
For sorted indexes, return the index label that is the latest among | ||
the labels that are not later than the passed index label. |
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.
I find this whole docstring a bit confusing to be honest. I think it's a complex method to document, but I think we can do better.
For the examples, I find this much clearer:
import pandas
idx = pandas.Index(['a', 'b', 'd', 'e'])
idx.asof('c')
For the description, it's difficult, but something like "Return the label from the index, or the previous if not found" would be something easier to understand for me.
For the rest looks quite good.
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.
It's hard to be completely understandable within a single line. But I'll try again using your suggestions. Thanks!
Codecov Report
@@ Coverage Diff @@
## master #20344 +/- ##
==========================================
- Coverage 91.82% 91.77% -0.05%
==========================================
Files 152 153 +1
Lines 49248 49270 +22
==========================================
- Hits 45222 45220 -2
- Misses 4026 4050 +24
Continue to review full report at Codecov.
|
Hello @datapythonista I've updated the documentation based on your suggestions. Do you think it's okay now to be merged? |
pandas/core/indexes/base.py
Outdated
>>> idx_not_sorted = pd.Index([13, 20, 18]) | ||
>>> idx_not_sorted.asof(18) | ||
Traceback (most recent call last): | ||
ValueError: index must be monotonic increasing or decreasing |
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.
Looks great. The only think that comes to my mind is if it'd make sense to use dates in the examples. I think the example with integers is simpler, and easier to understand. But I'd say in practice the method is only used with dates.
Like, if you want to know the price of a stock, and you say, give me the price asof
1st of January. The 1st of January the markets are closed, so the price returned would be the one of the 31st of December or the last day the markets were open.
I'm not quite sure what would be the best. If you think you can improve the docstring with the user case I just mentioned, that would be great. Otherwise looks good to me.
And may be we could also add Series.asof
and pandas.merge_asof
to the See Also section.
Thanks for the good work.
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.
Thanks for the feedback! I've updated the docs using your suggestions.
pandas/core/indexes/base.py
Outdated
------- | ||
object : The passed label if it is in the index. The previous label | ||
if the passed label is not in the sorted index, or NaN if there | ||
is no such label. |
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.
Looks great, just one minor formatting thing. The description goes to the next line, and the colon is not required. Also you can add backticks around the NaN
. For the rest is perfect, really like this final result.
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.
lgtm. Great job!
Not exactly sure how to proceed now. Should I ping a core developer and ask for merge? |
@DataOmbudsman no need for that. Project maintainers and core developers are in most cases volunteers, that use their spare time to work on the projects. They will take a look at this when they have the time. In many cases that will be in few hours or couple of days. In other cases it can take weeks. You just need to wait. If you check it, you'll see that there are 165 pull requests like yours open. Be patient, and work in something else if you've got the time. :) |
@datapythonista All right, thanks for the clarification. :) |
Thanks @DataOmbudsman! Sorry for the delay on our end. Great docstring! |
* DOC: update the pd.Index.asof docstring * clearer descriptions, restructured examples. * extended See Also section, dates instead of integers in Examples * minor formatting
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks:
If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.