Skip to content

BUG: to_datetime with unit mapping ignores utc and box arguments #23760

Closed
@mroeschke

Description

@mroeschke
In [12]: pd.__version__
Out[12]: '0.24.0.dev0+1040.g24bce1a5f'

In [13]: df = pd.DataFrame({'year': [2015, 2016],
    ...:                        'month': [2, 3],
    ...:                        'day': [4, 5]})
    ...:

In [14]: pd.to_datetime(df, box=False)
Out[14]:
0   2015-02-04
1   2016-03-05
dtype: datetime64[ns]

In [15]: pd.to_datetime(df, utc=True)
Out[15]:
0   2015-02-04
1   2016-03-05
dtype: datetime64[ns]

These arguments need to be handled directly in this function or the output

result = _assemble_from_unit_mappings(arg, errors=errors)

Expected Output

In [16]: pd.to_datetime(df, box=False).values
Out[16]:
array(['2015-02-04T00:00:00.000000000', '2016-03-05T00:00:00.000000000'],
      dtype='datetime64[ns]')

In [17]: pd.to_datetime(df, utc=True).dt.tz_localize('UTC')
Out[17]:
0   2015-02-04 00:00:00+00:00
1   2016-03-05 00:00:00+00:00
dtype: datetime64[ns, UTC]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions