Skip to content

Timestamps with different same tzinfo but different tzinfo type (datetime.timezone vs pytz.UTC) #33002

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
rooom13 opened this issue Mar 25, 2020 · 1 comment

Comments

@rooom13
Copy link

rooom13 commented Mar 25, 2020

Code Sample, a copy-pastable example if possible

import pytz
import datetime
import pandas as pd
date = pd.Timestamp("13-12-2020",tzinfo=datetime.timezone.utc)
date2 = pd.Timestamp("12-12-2020",tzinfo=pytz.UTC)
date - date2

>>> Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "pandas/_libs/tslibs/c_timestamp.pyx", line 300, in
 pandas._libs.tslibs.c_timestamp._Timestamp.__sub__
TypeError: Timestamp subtraction must have the same timezones or no timezones

Problem description

Current's timezone comparison is not timzone object type sensitive. Even if two dates are UTC but different tzinfo object (e.g: datetime.timezone.utc and pytz.UTC) they will be considered different timezones.
This could lead to unstabilitites since a Timestamp can have both obejct types as tzinfo

Expected Output

import pytz
import datetime
import pandas as pd
date = pd.Timestamp("13-12-2020",tzinfo=datetime.timezone.utc)
date2 = pd.Timestamp("12-12-2020",tzinfo=pytz.UTC)
date - date2
>>> Timedelta('1 days 00:00:00')

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit : None
python : 3.6.9.final.0
python-bits : 64
OS : Linux
OS-release : 4.4.0-18362-Microsoft
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.3
numpy : 1.18.2
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 45.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@mroeschke
Copy link
Member

Thanks for the report. This is a duplicate (underlying) issue of #32619

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants