Skip to content

Commit

Permalink
ENH: Don't infer WOM-5MON if we don't support it (pandas-dev#9425)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinc authored and craustin committed May 30, 2015
1 parent 2709f77 commit 1400bfa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ Bug Fixes
- Bug in GroupBy.get_group raises ValueError when group key contains NaT (:issue:`6992`)


- Bug where infer_freq infers timerule (WOM-5XXX) unsupported by to_offset (:issue:`9425`)
4 changes: 3 additions & 1 deletion pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,9 @@ def _get_wom_rule(self):
return None

week_of_months = unique((self.index.day - 1) // 7)
if len(week_of_months) > 1:
# Only attempt to infer up to WOM-4. See #9425
week_of_months = week_of_months[week_of_months < 4]
if len(week_of_months) == 0 or len(week_of_months) > 1:
return None

# get which week
Expand Down
10 changes: 10 additions & 0 deletions pandas/tseries/tests/test_frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ def test_week_of_month(self):
for i in range(1, 5):
self._check_generated_range('1/1/2000', 'WOM-%d%s' % (i, day))

def test_fifth_week_of_month(self):
# Only supports freq up to WOM-4. See #9425
func = lambda: date_range('2014-01-01', freq='WOM-5MON')
self.assertRaises(ValueError, func)

def test_fifth_week_of_month_infer(self):
# Only attempts to infer up to WOM-4. See #9425
index = DatetimeIndex(["2014-03-31", "2014-06-30", "2015-03-30"])
assert frequencies.infer_freq(index) is None

def test_week_of_month_fake(self):
#All of these dates are on same day of week and are 4 or 5 weeks apart
index = DatetimeIndex(["2013-08-27","2013-10-01","2013-10-29","2013-11-26"])
Expand Down

0 comments on commit 1400bfa

Please sign in to comment.