Skip to content

BUG: to_datetime with box=False returning DatetimeIndex with mixed naive and aware datetime.datetimes #23722

Closed
@mroeschke

Description

@mroeschke

xref #23702 (comment)

In [1]: pd.__version__
Out[1]: '0.24.0.dev0+1022.ga23f90142'

In [2]: import pytz; import datetime

In [3]: pd.to_datetime([datetime.datetime(2018, 1, 1), datetime.datetime(2018, 1, 1, tzinfo=pytz.UTC)], box=False)
Out[3]: DatetimeIndex(['2018-01-01 00:00:00+00:00', '2018-01-01 00:00:00+00:00'], dtype='datetime64[ns, UTC]', freq=None)

The current output also is incorrect if box=True I believe since the first argument is getting coerced to UTC.

Expected Result

In [3]: pd.to_datetime([datetime.datetime(2018, 1, 1), datetime.datetime(2018, 1, 1, tzinfo=pytz.UTC)], box=False)
Out[3]:
array([datetime.datetime(2018, 1, 1, 0, 0),
       datetime.datetime(2018, 1, 1, 0, 0, tzinfo=<UTC>)], dtype=object)

In [4]: pd.to_datetime([datetime.datetime(2018, 1, 1), datetime.datetime(2018, 1, 1, tzinfo=pytz.UTC)], box=True)
Out[4]: Index([2018-01-01 00:00:00, 2018-01-01 00:00:00+00:00], dtype='object')

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions