We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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.
Run python as PYTHONOPTIMIZE, option -O:
python -O
import pickle import pandas as pd idx = pd.date_range('2021-01-01', '2021-01-02', freq='D') idx_dump = pickle.dumps(idx) pickle.loads(idx_dump) Traceback (most recent call last): File "<stdin>", line 1, in <module> File ".../lib/python3.7/site-packages/pandas/core/indexes/datetimes.py", line 61, in _new_DatetimeIndex result = cls._simple_new(dta, **d) TypeError: _simple_new() got an unexpected keyword argument 'tz'
These dict operations go under the 'assert' statement:
# pandas/core/indexes/datetimes.py def _new_DatetimeIndex(cls, d): ... if key in d: assert d.pop(key) == getattr(dta, key) ...
which are ignored in PYTHONOPTIMIZED mode. As a fix, bring dict pop operation out of the assert statement.
DatetimeIndex(['2021-01-01', '2021-01-02'], dtype='datetime64[ns]', freq='D')
pd.show_versions()
commit : 7c48ff4 python : 3.7.9.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 : en_GB.UTF-8 LOCALE : en_GB.UTF-8
pandas : 1.2.5 numpy : 1.20.3 pytz : 2021.1 dateutil : 2.8.1 pip : 21.1.2 setuptools : 57.0.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : 4.6.3 html5lib : 1.1 pymysql : None psycopg2 : 2.8.6 (dt dec pq3 ext lo64) jinja2 : None IPython : 7.20.0 pandas_datareader: None bs4 : None bottleneck : None fsspec : None fastparquet : None gcsfs : None matplotlib : None numexpr : None odfpy : None openpyxl : 3.0.7 pandas_gbq : None pyarrow : None pyxlsb : None s3fs : None scipy : 1.6.3 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : 1.2.0 xlwt : None numba : None
The text was updated successfully, but these errors were encountered:
Thanks @GorAlexander for the report - want to submit a PR?
Sorry, something went wrong.
Hi @MarcoGorelli , just created the PR GH42866. Not sure if guideline checkpoints would pass.
Successfully merging a pull request may close this issue.
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
Run python as PYTHONOPTIMIZE, option -O:
Problem description
These dict operations go under the 'assert' statement:
which are ignored in PYTHONOPTIMIZED mode.
As a fix, bring dict pop operation out of the assert statement.
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 7c48ff4
python : 3.7.9.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 : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.2.5
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.2
setuptools : 57.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : None
IPython : 7.20.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: