Closed
Description
from test_mixed_offsets_with_native_datetime_raises
vals = [
"nan",
pd.Timestamp("1990-01-01"),
"2015-03-14T16:15:14.123-08:00",
"2019-03-04T21:56:32.620-07:00",
None,
]
ser = pd.Series(vals)
As expected, this comes back as object-dtype, but it also does some casting:
>>> ser
0 NaT
1 1990-01-01 00:00:00
2 2015-03-14 16:15:14.123000-08:00
3 2019-03-04 21:56:32.620000-07:00
4 None
dtype: object
ser[0]
is a str "NaT" and ser[[2, 3]]
are stdlib datetime objects. ser[1] and ser[4] are unchanged.
This casting is done inside a call to to_datetime
, but has the surprising effect of not being idempotent:
>>> pd.to_datetime(ser)
ValueError: Tz-aware datetime.datetime cannot be converted to datetime64 unless utc=True
I'd expect ser
to be constructed without doing any casting.