Skip to content

Commit 6789ef8

Browse files
committed
ENH: Support for "52–53-week fiscal year" / "4–4–5 calendar" and
LastWeekOfMonth DateOffset. - Added ``LastWeekOfMonth`` DateOffset - Added ``FY5253LastOfMonthQuarter``, ``FY5253LastOfMonth``, ``FY5253NearestEndMonth``, and ``FY5253NearestEndMonthQuarter`` DateOffsets
1 parent 609d6a6 commit 6789ef8

File tree

4 files changed

+794
-32
lines changed

4 files changed

+794
-32
lines changed

doc/source/release.rst

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ New features
5959
- Added ``isin`` method to DataFrame (:issue:`4211`)
6060
- Clipboard functionality now works with PySide (:issue:`4282`)
6161
- New ``extract`` string method returns regex matches more conveniently (:issue:`4685`)
62+
- Added ``LastWeekOfMonth`` DateOffset (:issue:`4637`)
63+
- Added ``FY5253LastOfMonthQuarter``, ``FY5253LastOfMonth``,
64+
``FY5253NearestEndMonth``, and ``FY5253NearestEndMonthQuarter``
65+
DateOffsets (:issue:`4511`)
6266

6367
Improvements to existing features
6468
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pandas/tseries/frequencies.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def get_freq_code(freqstr):
9292
code = _period_str_to_code(freqstr[0])
9393
stride = freqstr[1]
9494
except:
95+
if com.is_integer(freqstr[1]):
96+
raise
9597
code = _period_str_to_code(freqstr[1])
9698
stride = freqstr[0]
9799
return code, stride
@@ -367,9 +369,27 @@ def get_period_alias(offset_str):
367369

368370
for _i, _weekday in enumerate(['MON', 'TUE', 'WED', 'THU', 'FRI']):
369371
for _iweek in range(4):
372+
offset = offsets.WeekOfMonth(week=_iweek, weekday=_i)
373+
#TODO: Read the _name from offset.rule_code
370374
_name = 'WOM-%d%s' % (_iweek + 1, _weekday)
371-
_offset_map[_name] = offsets.WeekOfMonth(week=_iweek, weekday=_i)
375+
_offset_map[_name] = offset
372376
_rule_aliases[_name.replace('-', '@')] = _name
377+
378+
def add_offset_to_map(offset):
379+
_name = offset.rule_code
380+
_offset_map[_name] = offset
381+
382+
for _weekday in range(7):
383+
for _imonth in range(1,12+1):
384+
385+
for cls in [offsets.FY5253LastOfMonth, offsets.FY5253NearestEndMonth]:
386+
offset = cls(startingMonth=_imonth, weekday=_weekday)
387+
add_offset_to_map(offset)
388+
389+
for qtr_with_extra_week in range(1,4+1):
390+
for cls in [offsets.FY5253LastOfMonthQuarter, offsets.FY5253NearestEndMonthQuarter]:
391+
offset = cls(startingMonth=_imonth, weekday=_weekday, qtr_with_extra_week=qtr_with_extra_week)
392+
add_offset_to_map(offset)
373393

374394
# Note that _rule_aliases is not 1:1 (d[BA]==d[A@DEC]), and so traversal
375395
# order matters when constructing an inverse. we pick one. #2331
@@ -542,9 +562,6 @@ def get_legacy_offset_name(offset):
542562
name = _offset_names.get(offset)
543563
return _legacy_reverse_map.get(name, name)
544564

545-
get_offset_name = get_offset_name
546-
547-
548565
def get_standard_freq(freq):
549566
"""
550567
Return the standardized frequency string
@@ -744,7 +761,7 @@ def _period_str_to_code(freqstr):
744761
try:
745762
freqstr = freqstr.upper()
746763
return _period_code_map[freqstr]
747-
except:
764+
except KeyError:
748765
alias = _period_alias_dict[freqstr]
749766
return _period_code_map[alias]
750767

0 commit comments

Comments
 (0)