Skip to content

Treatment of Pre-Epoch datetimes in windows #32225

Closed
@Jacob-Bishop

Description

@Jacob-Bishop

Code Sample

import datetime
datetime.datetime(1953,1,23,0).astimezone(datetime.timezone(datetime.timedelta(days=-1, seconds=57600), 'Pacific Standard Time'))

Problem description

pandas._libs.tslibs.tzconversion._tz_convert_tzlocal_utc calls dt.astimezone(), which fails on Windows for pre-Epoch datetimes (see, e.g., code sample above) with OSError: [Errno 22] Invalid argument. This appears to be related to this issue dateutil/dateutil#197, where time.localtime() can't take negative values on Windows.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit : None python : 3.7.6.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.25.3
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.2.0.post20200210
Cython : None
pytest : None
hypothesis : None
sphinx : 2.4.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.4.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.9.0
pandas_datareader: None
bs4 : 4.8.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : 3.0.0
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.2
sqlalchemy : None
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None

Edit

The error appears to be in the datetutil module, not directly in datetime. See the stacktrace below:

Exception ignored in: 'pandas._libs.tslibs.tzconversion._tz_convert_tzlocal_utc' Traceback (most recent call last): File "C:\Users\jbishop\AppData\Roaming\Python\Python37\site-packages\dateutil\tz\_common.py", line 144, in fromutc return f(self, dt) File "C:\Users\jbishop\AppData\Roaming\Python\Python37\site-packages\dateutil\tz\_common.py", line 258, in fromutc dt_wall = self._fromutc(dt) File "C:\Users\jbishop\AppData\Roaming\Python\Python37\site-packages\dateutil\tz\_common.py", line 222, in _fromutc dtoff = dt.utcoffset() File "C:\Users\jbishop\AppData\Roaming\Python\Python37\site-packages\dateutil\tz\tz.py", line 222, in utcoffset if self._isdst(dt): File "C:\Users\jbishop\AppData\Roaming\Python\Python37\site-packages\dateutil\tz\tz.py", line 291, in _isdst dstval = self._naive_is_dst(dt) File "C:\Users\jbishop\AppData\Roaming\Python\Python37\site-packages\dateutil\tz\tz.py", line 260, in _naive_is_dst return time.localtime(timestamp + time.timezone).tm_isdst OSError: [Errno 22] Invalid argument

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions