Credo che questo problema sia già stato risolto in alcune versioni. Ora il comportamento dello date_range
è coerente, includendo sempre lo start
e lo la fine dello DatetimeIndex
sempre < = end
. E anche il formato di output è diventato carino.
seguito il codice utilizza panda 0.17.0:
In [1]: import pandas as pd
In [2]: pd.date_range(start='2014-06-09 15:36:55',
...: end='2014-06-09 15:37:46',
...: freq='20s')
Out[2]:
DatetimeIndex(['2014-06-09 15:36:55', '2014-06-09 15:37:15',
'2014-06-09 15:37:35'],
dtype='datetime64[ns]', freq='20S')
In [3]: pd.date_range(start='2014-06-09 15:36:55',
end='2014-06-09 15:37:46',
freq='10s')
Out[3]:
DatetimeIndex(['2014-06-09 15:36:55', '2014-06-09 15:37:05',
'2014-06-09 15:37:15', '2014-06-09 15:37:25',
'2014-06-09 15:37:35', '2014-06-09 15:37:45'],
dtype='datetime64[ns]', freq='10S')
In [4]: pd.date_range(start='2014-06-09 15:36:55',
end='2014-06-09 15:37:46',
freq='15s')
Out[4]:
DatetimeIndex(['2014-06-09 15:36:55', '2014-06-09 15:37:10',
'2014-06-09 15:37:25', '2014-06-09 15:37:40'],
dtype='datetime64[ns]', freq='15S')
In [5]: pd.date_range(start='2014-06-09 15:36:55',
end='2014-06-09 15:37:46',
freq='1s')
Out[5]:
DatetimeIndex(['2014-06-09 15:36:55', '2014-06-09 15:36:56',
...... ......
'2014-06-09 15:37:45', '2014-06-09 15:37:46'],
dtype='datetime64[ns]', freq='S')
Nota che la fine del DatetimeIndex
non supera mai end
data di date_range
.
Direi che sta arrotondando al limite di frequenza più vicino. 46 è più vicino a 55 che a 35 (20 secondi prima), ma più vicino a 45 a 55. Tuttavia, sono d'accordo che è un comportamento confuso. Potrebbe valere la pena chiedere la mailing list dei panda e/o sollevare un bug nel tracker. – BrenBarn
La mia ipotesi è che mentre la corrente