Skip to content

BUG: first("2M") returning incorrect results #38446

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 19, 2020
Merged

Conversation

phofl
Copy link
Member

@phofl phofl commented Dec 13, 2020

This would fix #29623 for offsets with n > 1
cc @simonjayhawkins

@simonjayhawkins
Copy link
Member

Thanks @phofl for the quick response.

I'm not sure where this leaves us w.r.t. backports. whether we should backport #38331 (i.e. reopen #38436) and then backport this as well.

or let these changes sit in master for a while (and move release note added in #38331 to 1.3 whatsnew)

@phofl
Copy link
Member Author

phofl commented Dec 13, 2020

If we decide to backport, we could cherry pick this one on top of the other Commit. But I am not quite sure either if we should backport.

@jreback
Copy link
Contributor

jreback commented Dec 13, 2020

we can just revert the original and then merge to master

@phofl
Copy link
Member Author

phofl commented Dec 13, 2020

Oh right, that would work. Should I open a Revert PR?

@simonjayhawkins
Copy link
Member

#38448

@phofl
Copy link
Member Author

phofl commented Dec 13, 2020

Ok, thx. Will adjust this one after the other is merged

@simonjayhawkins
Copy link
Member

after the revert is merged, will reopen issue and change milestone. so can update the OP here to close issue again.

…623_fix

� Conflicts:
�	pandas/core/generic.py
�	pandas/tests/frame/methods/test_first_and_last.py
@phofl
Copy link
Member Author

phofl commented Dec 13, 2020

Done. This fixes both cases now.

@@ -607,6 +607,7 @@ Datetimelike
- Bug in :meth:`Series.isin` with ``datetime64[ns]`` dtype and :meth:`.DatetimeIndex.isin` failing to consider timezone-aware and timezone-naive datetimes as always different (:issue:`35728`)
- Bug in :meth:`Series.isin` with ``PeriodDtype`` dtype and :meth:`PeriodIndex.isin` failing to consider arguments with different ``PeriodDtype`` as always different (:issue:`37528`)
- Bug in :class:`Period` constructor now correctly handles nanoseconds in the ``value`` argument (:issue:`34621` and :issue:`17053`)
- Bug in :meth:`DataFrame.first` and :meth:`Series.first` returning two months for offset one month when first day is last calendar day (:issue:`29623`)
Copy link
Member

Choose a reason for hiding this comment

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

so we have three options

  1. include in 1.2
  2. change to 1.3
  3. hold-off merging for a week or so, and then include in 1.2.1

i'm ok with 2 or 3, not so keen on 1.

Copy link
Member

Choose a reason for hiding this comment

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

3. hold-off merging for a week or so

actually, no harm in adding a 1.2.1 whatsnew now.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am fine with either one of them

Copy link
Contributor

Choose a reason for hiding this comment

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

ok let's push on 1.3

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@jreback jreback added this to the 1.3 milestone Dec 13, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

changes look fine, let' sput on 1.3

@@ -607,6 +607,7 @@ Datetimelike
- Bug in :meth:`Series.isin` with ``datetime64[ns]`` dtype and :meth:`.DatetimeIndex.isin` failing to consider timezone-aware and timezone-naive datetimes as always different (:issue:`35728`)
- Bug in :meth:`Series.isin` with ``PeriodDtype`` dtype and :meth:`PeriodIndex.isin` failing to consider arguments with different ``PeriodDtype`` as always different (:issue:`37528`)
- Bug in :class:`Period` constructor now correctly handles nanoseconds in the ``value`` argument (:issue:`34621` and :issue:`17053`)
- Bug in :meth:`DataFrame.first` and :meth:`Series.first` returning two months for offset one month when first day is last calendar day (:issue:`29623`)
Copy link
Contributor

Choose a reason for hiding this comment

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

ok let's push on 1.3

if not isinstance(offset, Tick) and offset.is_on_offset(self.index[0]):
# GH#29623 if first value is end of period, remove offset with n = 1
# before adding the real offset
end_date = end = self.index[0] - to_offset(offset.name) + offset
Copy link
Member

Choose a reason for hiding this comment

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

offset.base instead of to_offset(offset.name)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Better:) thx

@jreback jreback merged commit a4efa9f into pandas-dev:master Dec 19, 2020
@jreback
Copy link
Contributor

jreback commented Dec 19, 2020

thanks @phofl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: incorrect output of first('1M') in case if first index is the last day of the month
4 participants