Skip to content

BUG: Timezones are not preserved in Series.mode() output #41927

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
2 of 3 tasks
willsthompson opened this issue Jun 10, 2021 · 2 comments · Fixed by #44582
Closed
2 of 3 tasks

BUG: Timezones are not preserved in Series.mode() output #41927

willsthompson opened this issue Jun 10, 2021 · 2 comments · Fixed by #44582
Labels
Bug Timezones Timezone data dtype
Milestone

Comments

@willsthompson
Copy link

willsthompson commented Jun 10, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

import datetime
times = pd.Series([pd.Timestamp(datetime.datetime.now(), tz='US/Central') for n in range(5)])
times.dtype # datetime64[ns, US/Central] == pd.DatetimeTZDtype(tz='US/Central')
mode_result = times.mode()
mode_result.dtype # dtype('<M8[ns]') == np.dtype('datetime64[ns]')

Problem description

The Timestamps are normalized to (I think) UTC time, and the original timezone and offset are lost. Series.median() does preserve timezones, so I assumed this is just an unhandled edge case. I'm working around this using scipy.stats.mode, which does preserve timezones.

Expected Output

times.mode().dtype == pd.DatetimeTZDtype(tz='US/Central')

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2cb9652
python : 3.8.7.final.0
python-bits : 64
OS : Darwin
OS-release : 20.5.0
Version : Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.2.4
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 20.3.4
setuptools : 49.2.1
Cython : 0.29.14
pytest : 6.2.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : 2.11.3
IPython : 7.24.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 2.0.0
pyxlsb : None
s3fs : None
scipy : 1.6.1
sqlalchemy : 1.3.23
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
numba : None

@willsthompson willsthompson added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 10, 2021
@yasuomaidana
Copy link

Could you assign it to me?

@simonjayhawkins
Copy link
Member

from https://pandas.pydata.org/pandas-docs/dev/development/contributing.html#where-to-start

So, a good way to find an issue to start contributing to pandas is to check the list of unassigned good first issues and assign yourself one you like by writing a comment with the exact text take.

issues with "needs triage" labels should have some discussion before opening a PR.

@mroeschke mroeschke added Timezones Timezone data dtype and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 21, 2021
@jreback jreback added this to the 1.4 milestone Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants