-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Added Documentation to specify that DataFrame.last() needs the index to be sorted to deliver the expected results #38536
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
Conversation
Added Documentation mentioning that DataFrame.last() needs the index to be sorted to deliver the expected results
Fixed PEP8 Issues
Fixed PEP 8 Issues
pandas/core/generic.py
Outdated
@@ -8442,6 +8442,9 @@ def last(self: FrameOrSeries, offset) -> FrameOrSeries: | |||
When having a DataFrame with dates as index, this function can | |||
select the last few rows based on a date offset. | |||
|
|||
Note that for the last() method to work, the DatetimeIndex |
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.
Personal opinion but I'd rather rephrase the paragraph above to make this clear:
For a DataFrame with a sorted DatetimeIndex, this function selects the last few rows based on a date offset.
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.
Yeah this seems to be better, I wasn't thinking of changing the original section initially but if that's okay then I'll change that too thanks :)
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.
@arw2019 I did make the changes but I was wondering as was commented in the issue earlier as well do we need to raise an error message as well incase the index is not sorted?
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.
@arw2019 I did make the changes but I was wondering as was commented in the issue earlier as well do we need to raise an error message as well incase the index is not sorted?
It uses binary search under the hood (logarithmic time) so, given no extra information, vertifying sortedness (linear time) would degrade performance. If sortedness information is stored somehow then I agree we should throw but AFAIK it isn't in general for a DatetimeIndex.
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.
ohkk understood thanks 👍
As per recommendation changed the description for DataFrame.last() making it more concise
Removed trailing whitespace to fix PEP 8 Issues
Thanks @MarcoGorelli |
…to be sorted to deliver the expected results (pandas-dev#38536) * Update generic.py Added Documentation mentioning that DataFrame.last() needs the index to be sorted to deliver the expected results * Update generic.py Fixed PEP8 Issues * Update generic.py Fixed PEP 8 Issues * Update generic.py As per recommendation changed the description for DataFrame.last() making it more concise * Update generic.py Removed trailing whitespace to fix PEP 8 Issues
Added Documentation mentioning that DataFrame.last() needs the index to be sorted to deliver the expected results
Haven't yet worked on raising an error will work as advised
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff