Skip to content

Commit 1400bfa

Browse files
austinccraustin
austinc
authored andcommitted
ENH: Don't infer WOM-5MON if we don't support it (pandas-dev#9425)
1 parent 2709f77 commit 1400bfa

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/source/whatsnew/v0.17.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@ Bug Fixes
8989
- Bug in GroupBy.get_group raises ValueError when group key contains NaT (:issue:`6992`)
9090

9191

92+
- Bug where infer_freq infers timerule (WOM-5XXX) unsupported by to_offset (:issue:`9425`)

pandas/tseries/frequencies.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,9 @@ def _get_wom_rule(self):
935935
return None
936936

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

941943
# get which week

pandas/tseries/tests/test_frequencies.py

+10
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,16 @@ def test_week_of_month(self):
212212
for i in range(1, 5):
213213
self._check_generated_range('1/1/2000', 'WOM-%d%s' % (i, day))
214214

215+
def test_fifth_week_of_month(self):
216+
# Only supports freq up to WOM-4. See #9425
217+
func = lambda: date_range('2014-01-01', freq='WOM-5MON')
218+
self.assertRaises(ValueError, func)
219+
220+
def test_fifth_week_of_month_infer(self):
221+
# Only attempts to infer up to WOM-4. See #9425
222+
index = DatetimeIndex(["2014-03-31", "2014-06-30", "2015-03-30"])
223+
assert frequencies.infer_freq(index) is None
224+
215225
def test_week_of_month_fake(self):
216226
#All of these dates are on same day of week and are 4 or 5 weeks apart
217227
index = DatetimeIndex(["2013-08-27","2013-10-01","2013-10-29","2013-11-26"])

0 commit comments

Comments
 (0)