You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importpandasaspdimportdatetimets_to_datetime=pd.to_datetime(datetime.datetime(2018, 3, 8, 16, 58, 41, 182221, tzinfo=datetime.timezone.utc))
ts_utcnow=pd.Timestamp.utcnow()
ts_timestamp=pd.Timestamp(datetime.datetime(2018, 3, 8, 16, 58, 41, 182221, tzinfo=datetime.timezone.utc))
ts_to_datetime-ts_utcnow# Timestamp subtraction must have the same timezones or no timezonests_timestamp-ts_utcnow# same errorts_to_datetime-ts_timestamp# ok
Problem description
Timestamps constructed from datatime.datetime objects with UTC timezone have tz that is type datetime.timezone.utc but pd.Timestamp.utwnow() have tz that is pytz.UTC.
Expected Output
In [2]: ts_to_datetime-ts_utcnow---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
<ipython-input-2-5564b4c82b42>in<module>()
---->1ts_to_datetime-ts_utcnowpandas/_libs/tslibs/timestamps.pyxinpandas._libs.tslibs.timestamps._Timestamp.__sub__()
TypeError: Timestampsubtractionmusthavethesametimezonesornotimezones
The main issue is that pandas do not yet support datetime.timezone objects. Currently pandas only supports pytz or dateutil timezone objects.
I anticipate pandas supporting datetime.timezone objects soon enough since it's part of the standard library and since pandas will drop Python 2 support, but it will require quite some work. Pull requests are always welcome!
mroeschke
changed the title
UTC Timestamps constructed from datetime.datetime cannot be compared to pandas Timestamps
UTC Timestamps constructed from datetime.datetime (with datetime.timezone.utc) cannot be compared to pandas Timestamps
Jul 30, 2018
Code Sample, a copy-pastable example if possible
Problem description
Timestamps constructed from
datatime.datetime
objects with UTC timezone havetz
that is typedatetime.timezone.utc
butpd.Timestamp.utwnow()
havetz
that ispytz.UTC
.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Darwin
OS-release: 15.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.23.3
pytest: 3.0.5
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.13.3
scipy: 0.19.1
pyarrow: 0.7.1
xarray: 0.9.6
IPython: 5.1.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: 0.4.0
matplotlib: 2.0.2
openpyxl: 2.4.1
xlrd: 1.1.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: 0.9999999
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: