-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: CustomBusinessMonthBegin(End) sometimes ignores extra offset (GH41356) #41488
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
BUG: CustomBusinessMonthBegin(End) sometimes ignores extra offset (GH41356) #41488
Conversation
doc/source/whatsnew/v1.3.0.rst
Outdated
@@ -971,6 +971,7 @@ Other | |||
- Bug in :func:`pandas.util.show_versions` where console JSON output was not proper JSON (:issue:`39701`) | |||
- Bug in :meth:`DataFrame.convert_dtypes` incorrectly raised ValueError when called on an empty DataFrame (:issue:`40393`) | |||
- Bug in :meth:`DataFrame.clip` not interpreting missing values as no threshold (:issue:`40420`) | |||
- Bug in :meth:`_CustomBusinessMonth.apply` not applying extra offset when initially rolled date `new` is already a business day (:issue:`41356`) |
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.
_CustomBusinessMonth is not user-facing. can this be phrased in terms of something users will directly see?
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 just re-phased the entry. Is it more along the line of what you were thinking?
datetime(2021, 3, 2): datetime(2021, 3, 30) + timedelta(days=1), | ||
}, | ||
), | ||
] |
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.
can you just put these directly in the paremeterize?
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 review! Will do.
As a side note, the existing tests for .apply
also put the case definition outside of parametrize
. Happy to quickly change these as well if you would like.
), | ||
] | ||
|
||
@pytest.mark.parametrize("case", apply_with_extra_offset_cases) |
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.
same
pandas/_libs/tslibs/offsets.pyx
Outdated
@@ -3350,7 +3350,13 @@ cdef class _CustomBusinessMonth(BusinessMixin): | |||
""" | |||
Define default roll function to be called in apply method. | |||
""" | |||
cbday = CustomBusinessDay(n=self.n, normalize=False, **self.kwds) | |||
if self.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.
isn't offset always defined?
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.
Yes, the purpose of the check here is to make sure we only pass in a zero self.offset
into CustomBusinessDay
(and that we do not do unnecessary copying of the kwd dict).
32ce31b
to
bc6d718
Compare
doc/source/whatsnew/v1.3.0.rst
Outdated
@@ -974,6 +974,7 @@ Other | |||
- Bug in :meth:`DataFrame.convert_dtypes` incorrectly raised ValueError when called on an empty DataFrame (:issue:`40393`) | |||
- Bug in :meth:`DataFrame.clip` not interpreting missing values as no threshold (:issue:`40420`) | |||
- Bug in :class:`Series` backed by :class:`DatetimeArray` or :class:`TimedeltaArray` sometimes failing to set the array's ``freq`` to ``None`` (:issue:`41425`) | |||
- Bug in :meth:`CustomBusinessMonthBegin` (:meth:`CustomBusinessMonthEnd`) not applying the extra ``offset`` parameter when beginning (end) of the target month is already a business day (:issue:`41356`) |
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.
you've given the class but not the method. Is it e.g. CustomBusinessMonthBegin.__add__
?
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.
Oops, my apologies. It should be corrected now. I mentioned the function .apply
to be more specific, but maybe I should say .__add__
to be more user-centric?
bc6d718
to
52bfd15
Compare
@jackzyliu can you merge master to resolve conflicts |
52bfd15
to
02f6ceb
Compare
Hi @simonjayhawkins, I just rebased after master, but some checks started failing and I can't replicate the failed tests offline. Examples:
These checks were successful before rebasing without any code change. What could be the issue here? |
The test_on_offset_implementations failure is a hypothesis failure so that maybe the reason it didn't fail before. may need to investigate that one further. The numpydev failures are a known issue. |
7068952
to
8cb2f65
Compare
Re-rebased after master. @simonjayhawkins
Previously,
I created a separate issue and pull request for this. |
8cb2f65
to
7b9a061
Compare
7b9a061
to
54c7070
Compare
Bumping up this PR for further review. Since we just released The failed test seem to come from master? Please let me know of further comments. Thanks. |
4a8fcec
to
ba151ef
Compare
@jreback @jbrockmendel @simonjayhawkins
Please let me know of further comments. Thanks! |
ba151ef
to
47bf257
Compare
…41356) CustomBusinessMonthBegin(End) does not apply extra offset when the initially rolled month begin (end) is already a business day.
de9c975
to
b85ba8d
Compare
b85ba8d
to
05c8ee8
Compare
Resolved conflict with master. Green. |
thanks @jackzyliu, sorry about the wait, lots of PRs :-> keep em coming! |
Problem description: _CustomBusinessMonth does not apply extra offset when initially rolled month begin
new
is already a business day. This happens because we currently use CustomBusinessDay.rollforward (rollback) to both 1) roll to a business day and 2) apply the extra offset.Fix: Separating the logic to 1) roll to a business day and 2) apply the extra offset.