Pandas `period_range` gives strange results

I want a pandas period range with an offset of 25 hours, and I saw that there are two ways to do this (see here ):

The first way is to use freq=25H , which I tried and gave the correct answer:

 import pandas as pd pd.period_range(start='2016-01-01 10:00', freq = '25H', periods = 10) 

and result

 PeriodIndex(['2016-01-01 10:00', '2016-01-02 11:00', '2016-01-03 12:00', '2016-01-04 13:00', '2016-01-05 14:00', '2016-01-06 15:00', '2016-01-07 16:00', '2016-01-08 17:00', '2016-01-09 18:00', '2016-01-10 19:00'], dtype='int64', freq='25H') 

The second method, using freq=1D1H , gave me a rather strange result:

 pd.period_range(start='2016-01-01 10:00', freq = '1D1H', periods = 10) 

and i got

  PeriodIndex(['1971-12-02 01:00', '1971-12-02 02:00', '1971-12-02 03:00', '1971-12-02 04:00', '1971-12-02 05:00', '1971-12-02 06:00', '1971-12-02 07:00', '1971-12-02 08:00', '1971-12-02 09:00', '1971-12-02 10:00'], dtype='int64', freq='25H') 

So 1D1H not a valid way to indicate frequency? How did 1971 come about? (I also tried using 1D1H as the frequency for the date_range() method, which gave the correct answer.)

 pd.date_range('2016-01-01 10:00', freq = '1D1H', periods = 10) DatetimeIndex(['2016-01-01 10:00:00', '2016-01-02 11:00:00', '2016-01-03 12:00:00', '2016-01-04 13:00:00', '2016-01-05 14:00:00', '2016-01-06 15:00:00', '2016-01-07 16:00:00', '2016-01-08 17:00:00', '2016-01-09 18:00:00', '2016-01-10 19:00:00'], dtype='datetime64[ns]', freq='25H') 

EDIT: it seems like with period_range() , although freq=1D1H does not work, freq=1H1D does. The reason is still unknown.

EDIT2: this has been identified as an error, see answer below.

+5
source share
1 answer

Bug fixed and GitHub reported .

EDIT: The fix has been merged and will be included in v0.19.

+5
source

All Articles