Skip to content

Treatment of Pre-Epoch datetimes in windows #32225

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
Jacob-Bishop opened this issue Feb 24, 2020 · 1 comment
Closed

Treatment of Pre-Epoch datetimes in windows #32225

Jacob-Bishop opened this issue Feb 24, 2020 · 1 comment

Comments

@Jacob-Bishop
Copy link

Jacob-Bishop commented Feb 24, 2020

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
@mroeschke
Copy link
Member

Thanks for the report.

As you mentioned, seems like a deeper bug with dateutil and Windows. We would prefer a fix upstream instead of patching it in pandas.

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