period_range creates wrong dates when freq has multiple offsets · Issue #13730 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import pandas as pd pd.version u'0.18.0' pd.period_range('2016-07-20', periods=4, freq='2H') PeriodIndex(['2016-07-20 00:00', '2016-07-20 02:00', '2016-07-20 04:00', '2016-07-20 06:00'], dtype='int64', freq='2H') pd.period_range('2016-07-20', periods=4, freq='2H30min') PeriodIndex(['1970-10-11 08:48', '1970-10-11 08:50', '1970-10-11 08:52', '1970-10-11 08:54'], dtype='int64', freq='150T') pd.period_range('2016-07-20', periods=4, freq='2H30T') PeriodIndex(['1970-10-11 08:48', '1970-10-11 08:50', '1970-10-11 08:52', '1970-10-11 08:54'], dtype='int64', freq='150T') pd.period_range('2016-07-20', periods=2, freq='1D1H') PeriodIndex(['1971-12-10 10:00', '1971-12-10 11:00'], dtype='int64', freq='25H')

date_range works fine:

>>> pd.date_range('2016-07-20', periods=4, freq='2H30T')
DatetimeIndex(['2016-07-20 00:00:00', '2016-07-20 02:30:00',
               '2016-07-20 05:00:00', '2016-07-20 07:30:00'],
              dtype='datetime64[ns]', freq='150T')

Expected Output

The freq is right, but I'd expect the PeriodIndex to start at 2016-07-20, not in 1970, and to display 2h30 increments, something like:

PeriodIndex(['2016-07-20 00:00', '2016-07-20 02:30', '2016-07-20 05:00', '2016-07-20 07:30'], dtype='int64', freq='150T')

Or, if freq that combine multiple offsets are note supported, to at least raise and error.

output of pd.show_versions()

INSTALLED VERSIONS


commit: None
python: 2.7.11.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.0
nose: 1.3.7
pip: 8.1.2
setuptools: 23.1.0
Cython: 0.24
numpy: 1.10.4
scipy: 0.17.1
statsmodels: 0.6.1
xarray: 0.7.2
IPython: 4.1.2
sphinx: 1.4.1
patsy: 0.4.1
dateutil: 2.5.2
pytz: 2016.3
blosc: 1.2.8
bottleneck: 1.1.0
tables: 3.2.2
numexpr: 2.6.0
matplotlib: 1.5.1
openpyxl: 2.3.4
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.9.2
lxml: 3.6.0
bs4: 4.4.1
html5lib: 0.999
httplib2: 0.9.2
apiclient: None
sqlalchemy: 1.0.12
pymysql: 0.6.7.None
psycopg2: None
jinja2: 2.8
boto: 2.40.0