REF/DEPR: DatetimeIndex constructor by jbrockmendel · Pull Request #23675 · pandas-dev/pandas (original) (raw)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would try to remove this special handling

Yah, the immediate goal is to pass fewer cases to to_datetime since it is painfully circular and hides weird behavior like this float-dtype behavior.

If If we just cast floats to int64 (and mask with iNaT) then exactly one test fails in tests.dtypes.test_missing. The behavior (in master) that is different between float vs int is that floats are treated as wall-times instead of UTC times. eg:

iarr = np.array([0], dtype='i8')
farr = np.array([0], dtype='f8')

>>> pd.DatetimeIndex(iarr)._data
array(['1970-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
>>> pd.DatetimeIndex(iarr, tz='US/Eastern')._data
array(['1970-01-01T00:00:00.000000000'], dtype='datetime64[ns]')

>>> pd.DatetimeIndex(farr)._data
array(['1970-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
>>> pd.DatetimeIndex(farr, tz='US/Eastern')._data
array(['1970-01-01T05:00:00.000000000'], dtype='datetime64[ns]')

I don't see any especially good reason why it should work this way, save for keeping this test working and not introducing breaking changes.