Skip to content

BUG: DatetimeIndex.astype doesn't fully handle tz aware dtypes #18951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jschendel opened this issue Dec 27, 2017 · 0 comments · Fixed by #18937
Closed

BUG: DatetimeIndex.astype doesn't fully handle tz aware dtypes #18951

jschendel opened this issue Dec 27, 2017 · 0 comments · Fixed by #18937
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype
Milestone

Comments

@jschendel
Copy link
Member

Code Sample, a copy-pastable example if possible

Setup:

In [2]: dti_naive = pd.date_range('2017-01-01', periods=4)
   ...: dti_east = pd.date_range('2017-01-01', periods=4, tz='US/Eastern')
   ...: dti_west = pd.date_range('2017-01-01', periods=4, tz='US/Pacific')
   ...:

Attempting to convert between aware always converts to UTC and becomes naive:

In [3]: dti_west.astype(dti_east.dtype)
Out[3]:
DatetimeIndex(['2017-01-01 08:00:00', '2017-01-02 08:00:00',
               '2017-01-03 08:00:00', '2017-01-04 08:00:00'],
              dtype='datetime64[ns]', freq='D')

Converting naive to aware does nothing:

In [4]: dti_naive.astype(dti_east.dtype)
Out[4]: DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04'], dtype='datetime64[ns]', freq='D')

Converting aware to naive appears to work:

In [5]: dti_west.astype(dti_naive.dtype)
Out[5]:
DatetimeIndex(['2017-01-01 08:00:00', '2017-01-02 08:00:00',
               '2017-01-03 08:00:00', '2017-01-04 08:00:00'],
              dtype='datetime64[ns]', freq='D')

Expected Output

For [3]:

In [3]: dti_west.astype(dti_east.dtype)
Out[3]:
DatetimeIndex(['2017-01-01 03:00:00-05:00', '2017-01-02 03:00:00-05:00',
               '2017-01-03 03:00:00-05:00', '2017-01-04 03:00:00-05:00'],
              dtype='datetime64[ns, US/Eastern]', freq='D')

For [4]:

In [4]: dti_naive.astype(dti_east.dtype)
Out[4]:
DatetimeIndex(['2017-01-01 00:00:00-05:00', '2017-01-02 00:00:00-05:00',
               '2017-01-03 00:00:00-05:00', '2017-01-04 00:00:00-05:00'],
              dtype='datetime64[ns, US/Eastern]', freq='D')

Output of pd.show_versions()

INSTALLED VERSIONS

commit: a18d725
python: 3.6.1.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.22.0.dev0+433.ga18d725
pytest: 3.1.2
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.13.1
scipy: 0.19.1
pyarrow: 0.6.0
xarray: 0.9.6
IPython: 6.1.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.2
feather: 0.4.0
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: None
html5lib: 0.999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: 0.1.0
pandas_gbq: None
pandas_datareader: None

@jreback jreback added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype labels Dec 27, 2017
@jreback jreback added this to the 0.23.0 milestone Dec 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants