It would be cool if the offset were kept. Perhaps even an error should be raised if not all of the Timestamp
s have the same offset
:
In [36]:
dti = pd.to_datetime([pd.Timestamp("2014-1-1", offset="M"),])
dti
Out[36]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-01-01]
Length: 1, Freq: None, Timezone: None
See #6560
Comment From: mroeschke
Timestamp no longer accepts the offset keyword (deprecated and removed). Closing.
Comment From: jbrockmendel
@mroeschke I think this is still an issue with the freq
keyword:
>>> pd.Timestamp('now', freq='D')
Timestamp('2018-07-07 08:17:00.395067', freq='D')
>>> pd.to_datetime(pd.Timestamp('now', freq='D'))
Timestamp('2018-07-07 08:17:08.939068', freq='D')
>>> pd.to_datetime([pd.Timestamp('now', freq='D')])
DatetimeIndex(['2018-07-07 08:17:14.227013'], dtype='datetime64[ns]', freq=None)
Comment From: mroeschke
Oh I see. I had also rationalized closing this in light of #15146, but I see you mentioned that removing freq from Timestamp is non-trivial. Do you believe that's still the case?
Comment From: jbrockmendel
Do you believe that's still the case?
Backwards-compat would be annoying, not sure if anyone would really complain though.
Getting rid of it would break a behavior that is nice for testing that (dti + other == [x + other for x in dti]).all()
. Probably not a good enough reason to keep the Timestamp.freq attribute if it isn't otherwise needed.
But as long as the attribute does exist, I think to_datetime
should preserve it.
Comment From: mroeschke
Sounds good. Reopening.
Comment From: jbrockmendel
@mroeschke didn't this get solved recently?
Comment From: mroeschke
This now works for the scalar case but still not the array case. But should the DatetimeIndex
have a freq in this case with just 1 element?
In [5]: pd.__version__
Out[5]: '0.24.0.dev0+1010.ge413c491e'
In [6]: pd.to_datetime(pd.Timestamp("2014-1-1", freq="M"))
Out[6]: Timestamp('2014-01-01 00:00:00', freq='M')
In [7]: pd.to_datetime([pd.Timestamp("2014-1-1", freq="M")])
Out[7]: DatetimeIndex(['2014-01-01'], dtype='datetime64[ns]', freq=None)
Comment From: lukemanley
This was once closed and then reopened due to Timestamp.freq
but can now be closed again since freq
has been deprecated and removed. closing