-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix FY5253 onOffset/apply bug, simplify #18877
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
pass | ||
else: | ||
assert False |
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.
Double-checked this, it cannot be reached. See new comment above re next_year.year
.
else: | ||
if next_year < other: | ||
n += 2 | ||
# TODO: Not hit in tests; UPDATE: looks impossible |
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.
Double-checked this, it cannot be reached. See new comment above re next_year.year
.
pass | ||
elif other == next_year: | ||
n += 1 | ||
# TODO: Not hit in tests |
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.
Double-checked this, it cannot be reached. See new comment above re next_year.year
.
target_month = datetime(dt.year, self.startingMonth, 1, | ||
tzinfo=dt.tzinfo) | ||
return shift_month(target_month, 0, 'end') | ||
# TODO: is this DST-safe? |
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.
non-issue b/c get_target_month_end
is only ever called with dt.tzinfo is None
pandas/tseries/offsets.py
Outdated
|
||
def _get_year_end_last(self, dt): | ||
current_year = datetime(dt.year, self.startingMonth, 1, | ||
tzinfo=dt.tzinfo) |
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.
only called with dt.tzinfo is None
That should be the last new one for a while... I hope. |
Close was accidental. |
@@ -158,17 +158,6 @@ def test_apply(self): | |||
|
|||
class TestFY5253NearestEndMonth(Base): | |||
|
|||
def test_get_target_month_end(self): | |||
assert (makeFY5253NearestEndMonth( |
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.
are these tests wrong?
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.
No, but get_target_month_end
is removed in this PR.
|
||
|
||
def test_fy5253_last_onoffset(): | ||
offset = FY5253(n=-5, startingMonth=5, variation="last", weekday=0) |
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.
add a comment to these tests about what you are testing. next person to come along will have no idea. add the issue number as well.
doc/source/whatsnew/v0.22.0.txt
Outdated
@@ -354,3 +354,4 @@ Other | |||
|
|||
- Improved error message when attempting to use a Python keyword as an identifier in a ``numexpr`` backed query (:issue:`18221`) | |||
- Bug in :class:`Timestamp` where comparison with an array of ``Timestamp`` objects would result in a ``RecursionError`` (:issue:`15183`) | |||
- Bug in :class:`FY5253` where ``datetime`` addition and subtraction incremented incorrectly in some corner cases (:issue:`18854`) |
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 give a typical case here, so a user would know to look closer about this.
Codecov Report
@@ Coverage Diff @@
## master #18877 +/- ##
==========================================
- Coverage 91.59% 91.57% -0.02%
==========================================
Files 150 150
Lines 48924 48911 -13
==========================================
- Hits 44813 44792 -21
- Misses 4111 4119 +8
Continue to review full report at Codecov.
|
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.
minor formatting. ping on green.
pandas/tseries/offsets.py
Outdated
@@ -1821,33 +1816,27 @@ def apply(self, other): | |||
prev_year = tslib._localize_pydatetime(prev_year, other.tzinfo) | |||
cur_year = tslib._localize_pydatetime(cur_year, other.tzinfo) | |||
next_year = tslib._localize_pydatetime(next_year, other.tzinfo) | |||
# Note: next_year.year == other.year + 1, so we will always |
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.
pls add a blank line (generally) before comments.
pandas/tseries/offsets.py
Outdated
return target_date + timedelta(days_forward) | ||
if self.variation == "last": | ||
days_forward = (wkday_diff % 7) - 7 | ||
# days_forward is always negative, so we always end up |
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.
here
pandas/tseries/offsets.py
Outdated
# variation == "nearest": | ||
days_forward = wkday_diff % 7 | ||
if days_forward <= 3: | ||
# The upcoming self.weekday is closer than the previous one |
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.
these comments are good, FYI (you only need a blank line when the indentation is the same)
Ping |
This is a blocker for addressing bugs in FY5253Quarter. |
lgtm. conflict in whatsnew. ping when pushed / green. |
ping |
thanks! |
Similar to #18875.
The actual bugfix here is just changing the comparison in
apply
fromother < whatever
tonorm < whatever
. The remaining edits toget_year_end
are orthogonal simplification (which I guess could go in a separate PR).git diff upstream/master -u -- "*.py" | flake8 --diff