Skip to content

BUG: DatetimeIndex.unique shifts tz-aware dates #21737

Closed
@danielwlogan

Description

@danielwlogan

Code Sample, a copy-pastable example if possible

import pandas as pd
start = pd.Timestamp('2018-7-3 2:00:00', tz='America/Los_Angeles')
end = start + pd.Timedelta('36H')
a = pd.DatetimeIndex(start=start, end=end, freq='12H')
a.normalize().unique()

Problem description

The normalize method correctly sets the DatetimeIndex to midnight but the unique method returns a new DatetimeIndex not set to midnight, rather it returns a DatetimeIndex time as if converted to UTC (07:00 in the example code) but still retains the correct timezone ('America/Los_Angeles' in the example code). The code returns:

DatetimeIndex(['2018-07-03 07:00:00-07:00', '2018-07-04 07:00:00-07:00'], dtype='datetime64[ns, America/Los_Angeles]', freq=None)

Expected Output

DatetimeIndex(['2018-07-03 00:00:00-07:00', '2018-07-04 00:00:00-07:00'], dtype='datetime64[ns, America/Los_Angeles]', freq=None)

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-24-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_CA.UTF-8
LOCALE: en_CA.UTF-8

pandas: 0.23.1
pytest: None
pip: 10.0.1
setuptools: 39.2.0
Cython: 0.28.3
numpy: 1.14.3
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.4.0
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: 1.2.7
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: 0.4.1
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeTestingpandas testing functions or related to the test suiteTimezonesTimezone data dtypeUnreliable TestUnit tests that occasionally failgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions