Skip to content

Commit

Permalink
ENH: Support for "52–53-week fiscal year" / "4–4–5 calendar" and
Browse files Browse the repository at this point in the history
LastWeekOfMonth DateOffset.
- Added ``LastWeekOfMonth`` DateOffset
- Added ``FY5253LastOfMonthQuarter``, ``FY5253LastOfMonth``,
``FY5253NearestEndMonth``, and ``FY5253NearestEndMonthQuarter``
DateOffsets
  • Loading branch information
cancan101 committed Sep 27, 2013
1 parent 609d6a6 commit 6789ef8
Show file tree
Hide file tree
Showing 4 changed files with 794 additions and 32 deletions.
4 changes: 4 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ New features
- Added ``isin`` method to DataFrame (:issue:`4211`)
- Clipboard functionality now works with PySide (:issue:`4282`)
- New ``extract`` string method returns regex matches more conveniently (:issue:`4685`)
- Added ``LastWeekOfMonth`` DateOffset (:issue:`4637`)
- Added ``FY5253LastOfMonthQuarter``, ``FY5253LastOfMonth``,
``FY5253NearestEndMonth``, and ``FY5253NearestEndMonthQuarter``
DateOffsets (:issue:`4511`)

Improvements to existing features
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
27 changes: 22 additions & 5 deletions pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def get_freq_code(freqstr):
code = _period_str_to_code(freqstr[0])
stride = freqstr[1]
except:
if com.is_integer(freqstr[1]):
raise
code = _period_str_to_code(freqstr[1])
stride = freqstr[0]
return code, stride
Expand Down Expand Up @@ -367,9 +369,27 @@ def get_period_alias(offset_str):

for _i, _weekday in enumerate(['MON', 'TUE', 'WED', 'THU', 'FRI']):
for _iweek in range(4):
offset = offsets.WeekOfMonth(week=_iweek, weekday=_i)
#TODO: Read the _name from offset.rule_code
_name = 'WOM-%d%s' % (_iweek + 1, _weekday)
_offset_map[_name] = offsets.WeekOfMonth(week=_iweek, weekday=_i)
_offset_map[_name] = offset
_rule_aliases[_name.replace('-', '@')] = _name

def add_offset_to_map(offset):
_name = offset.rule_code
_offset_map[_name] = offset

for _weekday in range(7):
for _imonth in range(1,12+1):

for cls in [offsets.FY5253LastOfMonth, offsets.FY5253NearestEndMonth]:
offset = cls(startingMonth=_imonth, weekday=_weekday)
add_offset_to_map(offset)

for qtr_with_extra_week in range(1,4+1):
for cls in [offsets.FY5253LastOfMonthQuarter, offsets.FY5253NearestEndMonthQuarter]:
offset = cls(startingMonth=_imonth, weekday=_weekday, qtr_with_extra_week=qtr_with_extra_week)
add_offset_to_map(offset)

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

get_offset_name = get_offset_name


def get_standard_freq(freq):
"""
Return the standardized frequency string
Expand Down Expand Up @@ -744,7 +761,7 @@ def _period_str_to_code(freqstr):
try:
freqstr = freqstr.upper()
return _period_code_map[freqstr]
except:
except KeyError:
alias = _period_alias_dict[freqstr]
return _period_code_map[alias]

Expand Down
Loading

0 comments on commit 6789ef8

Please sign in to comment.