Issues Creating Period with DateOffset as freq · Issue #4878 · pandas-dev/pandas (original) (raw)
Something seems wrong here:
print repr(pd.Period("2013-12", freq=pd.offsets.MonthEnd()))
correctly prints:
but:
print pd.Period("2013-12", freq=pd.offsets.BusinessMonthEnd())
leads to:
Traceback (most recent call last):
File "/home/alex/git/pandas/pandas/tseries/tests/test_52.py", line 29, in testName
a = pd.Period("2013-12", freq=BusinessMonthEnd())
File "/home/alex/git/pandas/pandas/tseries/period.py", line 121, in __init__
base, mult = _gfc(freq)
File "/home/alex/git/pandas/pandas/tseries/frequencies.py", line 92, in get_freq_code
code = _period_str_to_code(freqstr[0])
File "/home/alex/git/pandas/pandas/tseries/frequencies.py", line 757, in _period_str_to_code
alias = _period_alias_dict[freqstr]
KeyError: 'BM'
Strangely, the following both work:
In [10]: pd.date_range("2013-01","2013-10",freq=pd.offsets.MonthEnd())
Out[10]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-31 00:00:00, ..., 2013-09-30 00:00:00]
Length: 9, Freq: M, Timezone: None
In [11]: pd.date_range("2013-01","2013-10",freq=pd.offsets.BusinessMonthEnd())
Out[11]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-31 00:00:00, ..., 2013-09-30 00:00:00]
Length: 9, Freq: BM, Timezone: None