API: Period and PeriodIndex do not support some offset aliases · Issue #13871 · pandas-dev/pandas (original) (raw)
Period
and PeriodIndex
raise ValueError
when freq
is any of the following strings:
'BM', 'CBM', 'MS', 'BMS', 'CBMS', 'BQ', 'QS', 'BQS', 'BA', 'AS', 'BAS', 'BH'
date_range
is fine in all cases. Also confirmed on master
.
Possible related to #4878.
Code Sample, a copy-pastable example if possible
import pandas as pd
FREQS = ['B', 'C', 'D', 'W', 'M', 'BM', 'CBM', 'MS', 'BMS', 'CBMS', 'Q',
'BQ', 'QS', 'BQS', 'A', 'BA', 'AS', 'BAS', 'BH', 'H', 'T', 'min',
'S', 'L', 'U', 'N']
for freq in FREQS:
try:
pd.Period('2016-01-01', freq=freq)
except ValueError:
print('Cannot create Period with freq={}'.format(freq))
p = pd.Period('2016-01-01', freq='N')
try:
p.asfreq(freq)
except ValueError:
print('Cannot modify Period to freq={}'.format(freq))
try:
pd.PeriodIndex(start='2016-01-01', periods=10, freq=freq)
except ValueError:
print('Cannot create PeriodIndex with freq={}'.format(freq))
pi = pd.PeriodIndex(start='2016-01-01', periods=10, freq='N')
try:
pi.asfreq(freq)
except ValueError:
print('Cannot modify PeriodIndex to freq={}'.format(freq))
try:
pd.date_range(start='2016-01-01', periods=10, freq=freq)
except ValueError:
print('Cannot create date_range with freq={}'.format(freq))
Output
Cannot create Period with freq=BM
Cannot modify Period to freq=BM
Cannot create PeriodIndex with freq=BM
Cannot modify PeriodIndex to freq=BM
Cannot create Period with freq=CBM
Cannot modify Period to freq=CBM
Cannot create PeriodIndex with freq=CBM
Cannot modify PeriodIndex to freq=CBM
Cannot create Period with freq=MS
Cannot modify Period to freq=MS
Cannot create PeriodIndex with freq=MS
Cannot modify PeriodIndex to freq=MS
Cannot create Period with freq=BMS
Cannot modify Period to freq=BMS
Cannot create PeriodIndex with freq=BMS
Cannot modify PeriodIndex to freq=BMS
Cannot create Period with freq=CBMS
Cannot modify Period to freq=CBMS
Cannot create PeriodIndex with freq=CBMS
Cannot modify PeriodIndex to freq=CBMS
Cannot create Period with freq=BQ
Cannot modify Period to freq=BQ
Cannot create PeriodIndex with freq=BQ
Cannot modify PeriodIndex to freq=BQ
Cannot create Period with freq=QS
Cannot modify Period to freq=QS
Cannot create PeriodIndex with freq=QS
Cannot modify PeriodIndex to freq=QS
Cannot create Period with freq=BQS
Cannot modify Period to freq=BQS
Cannot create PeriodIndex with freq=BQS
Cannot modify PeriodIndex to freq=BQS
Cannot create Period with freq=BA
Cannot modify Period to freq=BA
Cannot create PeriodIndex with freq=BA
Cannot modify PeriodIndex to freq=BA
Cannot create Period with freq=AS
Cannot modify Period to freq=AS
Cannot create PeriodIndex with freq=AS
Cannot modify PeriodIndex to freq=AS
Cannot create Period with freq=BAS
Cannot modify Period to freq=BAS
Cannot create PeriodIndex with freq=BAS
Cannot modify PeriodIndex to freq=BAS
Cannot create Period with freq=BH
Cannot modify Period to freq=BH
Cannot create PeriodIndex with freq=BH
Cannot modify PeriodIndex to freq=BH
output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Darwin
OS-release: 15.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 23.0.0
Cython: 0.24
numpy: 1.11.0
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.2.0
sphinx: None
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: None
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None
None