Skip to content

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

Merged
merged 7 commits into from
Dec 28, 2017

Conversation

jbrockmendel
Copy link
Member

Similar to #18875.

The actual bugfix here is just changing the comparison in apply from other < whatever to norm < whatever. The remaining edits to get_year_end are orthogonal simplification (which I guess could go in a separate PR).

  • closes #xxxx
  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

pass
else:
assert False
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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?
Copy link
Member Author

@jbrockmendel jbrockmendel Dec 20, 2017

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


def _get_year_end_last(self, dt):
current_year = datetime(dt.year, self.startingMonth, 1,
tzinfo=dt.tzinfo)
Copy link
Member Author

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

@jbrockmendel
Copy link
Member Author

That should be the last new one for a while... I hope.

@jbrockmendel
Copy link
Member Author

Close was accidental.

@@ -158,17 +158,6 @@ def test_apply(self):

class TestFY5253NearestEndMonth(Base):

def test_get_target_month_end(self):
assert (makeFY5253NearestEndMonth(
Copy link
Contributor

Choose a reason for hiding this comment

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

are these tests wrong?

Copy link
Member Author

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)
Copy link
Contributor

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.

@jreback jreback added the Frequency DateOffsets label Dec 21, 2017
@@ -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`)
Copy link
Contributor

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.

@jreback jreback added the Bug label Dec 21, 2017
@codecov
Copy link

codecov bot commented Dec 22, 2017

Codecov Report

Merging #18877 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.94% <100%> (-0.02%) ⬇️
#single 41.17% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/tseries/offsets.py 97.07% <100%> (+0.28%) ⬆️
pandas/plotting/_converter.py 65.22% <0%> (-1.74%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80a5399...9f02521. Read the comment docs.

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.

minor formatting. ping on green.

@@ -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
Copy link
Contributor

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.

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
Copy link
Contributor

Choose a reason for hiding this comment

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

here

# variation == "nearest":
days_forward = wkday_diff % 7
if days_forward <= 3:
# The upcoming self.weekday is closer than the previous one
Copy link
Contributor

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)

@jreback jreback added this to the 0.23.0 milestone Dec 23, 2017
@jbrockmendel
Copy link
Member Author

Ping

@jbrockmendel
Copy link
Member Author

This is a blocker for addressing bugs in FY5253Quarter.

@jreback
Copy link
Contributor

jreback commented Dec 27, 2017

lgtm. conflict in whatsnew. ping when pushed / green.

@jbrockmendel
Copy link
Member Author

ping

@jreback jreback merged commit f42ae78 into pandas-dev:master Dec 28, 2017
@jreback
Copy link
Contributor

jreback commented Dec 28, 2017

thanks!

@jbrockmendel jbrockmendel deleted the offsets-fy5253 branch February 11, 2018 22:00
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.

2 participants