Skip to content

Backport PR #42871 on branch 1.3.x (BUG: GH42866 DatetimeIndex de-serializing fails in PYTHONOPTIMIZE mode) #42904

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.3.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Bug fixes
- Bug in :meth:`pandas.read_excel` modifies the dtypes dictionary when reading a file with duplicate columns (:issue:`42462`)
- 1D slices over extension types turn into N-dimensional slices over ExtensionArrays (:issue:`42430`)
- :meth:`.Styler.hide_columns` now hides the index name header row as well as column headers (:issue:`42101`)
- Bug in de-serializing datetime indexes in PYTHONOPTIMIZED mode (:issue:`42866`)
-

.. ---------------------------------------------------------------------------

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def _new_DatetimeIndex(cls, d):
# These are already stored in our DatetimeArray; if they are
# also in the pickle and don't match, we have a problem.
if key in d:
assert d.pop(key) == getattr(dta, key)
assert d[key] == getattr(dta, key)
d.pop(key)
result = cls._simple_new(dta, **d)
else:
with warnings.catch_warnings():
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/test_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ def test_oo_optimizable():
subprocess.check_call([sys.executable, "-OO", "-c", "import pandas"])


def test_oo_optimized_datetime_index_unpickle():
# GH 42866
subprocess.check_call(
[
sys.executable,
"-OO",
"-c",
(
"import pandas as pd, pickle; "
"pickle.loads(pickle.dumps(pd.date_range('2021-01-01', periods=1)))"
),
]
)


@tm.network
# Cython import warning
@pytest.mark.filterwarnings("ignore:pandas.util.testing is deprecated")
Expand Down