Skip to content

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

Merged
merged 5 commits into from
Dec 17, 2020

Conversation

aflah02
Copy link
Contributor

@aflah02 aflah02 commented Dec 17, 2020

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

Added Documentation mentioning that DataFrame.last() needs the index to be sorted to deliver the expected results
@pep8speaks
Copy link

pep8speaks commented Dec 17, 2020

Hello @aflah02! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-12-17 08:21:54 UTC

Fixed PEP8 Issues
Fixed PEP 8  Issues
@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

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?

Copy link
Member

@arw2019 arw2019 Dec 17, 2020

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.

Copy link
Contributor Author

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
@aflah02 aflah02 requested a review from arw2019 December 17, 2020 11:58
@MarcoGorelli
Copy link
Member

Looks good, thanks @aflah02 (and thanks @arw2019 for reviewing!)

@MarcoGorelli MarcoGorelli merged commit 8fd2d0c into pandas-dev:master Dec 17, 2020
@MarcoGorelli MarcoGorelli added this to the 1.3 milestone Dec 17, 2020
@aflah02
Copy link
Contributor Author

aflah02 commented Dec 17, 2020

Thanks @MarcoGorelli

@aflah02 aflah02 deleted the docupdate branch December 17, 2020 16:55
luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: DataFrame.last() needs the index to be sorted to deliver the expected results
4 participants