-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: fix infer frequency for business daily #16683
Changes from 2 commits
4c0a181
310d412
84ca63a
b79733a
60f55a7
d3932dd
6042aa4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,7 +567,7 @@ class TestSlicing(object): | |
|
||
def test_timedelta(self): | ||
# this is valid too | ||
index = date_range('1/1/2000', periods=50, freq='B') | ||
index = date_range('1/1/2000', periods=50, freq='D') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can u also test with B |
||
shifted = index + timedelta(1) | ||
back = shifted + timedelta(-1) | ||
assert tm.equalContents(index, back) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -504,9 +504,14 @@ def test_raise_if_too_few(self): | |
pytest.raises(ValueError, frequencies.infer_freq, index) | ||
|
||
def test_business_daily(self): | ||
index = _dti(['12/31/1998', '1/3/1999', '1/4/1999']) | ||
index = _dti(['01/01/1999', '1/4/1999', '1/5/1999']) | ||
assert frequencies.infer_freq(index) == 'B' | ||
|
||
def test_business_daily_look_alike(self): | ||
# 'weekend' (2-day gap) in wrong place | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add the issue number as a comment |
||
index = _dti(['12/31/1998', '1/3/1999', '1/4/1999']) | ||
assert frequencies.infer_freq(index) is None | ||
|
||
def test_day(self): | ||
self._check_tick(timedelta(1), 'D') | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -975,8 +975,7 @@ def _infer_daily_rule(self): | |
else: | ||
return _maybe_add_count('D', days) | ||
|
||
# Business daily. Maybe | ||
if self.day_deltas == [1, 3]: | ||
if self._is_business_daily(): | ||
return 'B' | ||
|
||
wom_rule = self._get_wom_rule() | ||
|
@@ -1012,6 +1011,17 @@ def _get_monthly_rule(self): | |
return {'cs': 'MS', 'bs': 'BMS', | ||
'ce': 'M', 'be': 'BM'}.get(pos_check) | ||
|
||
def _is_business_daily(self): | ||
if self.day_deltas != [1, 3]: # quick check: cannot be business daily | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put the comment on the line above (causes lint failure as line too long) |
||
return False | ||
# probably business daily, but need to confirm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add blank line before comment |
||
first_weekday = self.index[0].weekday() | ||
shifts = np.diff(np.asarray(self.index).view('i8')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
shifts = np.floor_divide(shifts, _ONE_DAY) | ||
weekdays = np.mod(first_weekday + np.cumsum(shifts), 7) | ||
return np.all(((weekdays == 0) & (shifts == 3)) | | ||
((weekdays > 0) & (weekdays <= 4) & (shifts == 1))) | ||
|
||
def _get_wom_rule(self): | ||
# wdiffs = unique(np.diff(self.index.week)) | ||
# We also need -47, -49, -48 to catch index spanning year boundary | ||
|
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.
move to 0.21.0