Skip to content

Commit 4a61bf6

Browse files
Backport PR #42871: BUG: GH42866 DatetimeIndex de-serializing fails in PYTHONOPTIMIZE mode (#42904)
Co-authored-by: Alexander Gorodetsky <[email protected]>
1 parent 02f066a commit 4a61bf6

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

doc/source/whatsnew/v1.3.2.rst

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Bug fixes
3333
- Bug in :meth:`pandas.read_excel` modifies the dtypes dictionary when reading a file with duplicate columns (:issue:`42462`)
3434
- 1D slices over extension types turn into N-dimensional slices over ExtensionArrays (:issue:`42430`)
3535
- :meth:`.Styler.hide_columns` now hides the index name header row as well as column headers (:issue:`42101`)
36+
- Bug in de-serializing datetime indexes in PYTHONOPTIMIZED mode (:issue:`42866`)
37+
-
3638

3739
.. ---------------------------------------------------------------------------
3840

pandas/core/indexes/datetimes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def _new_DatetimeIndex(cls, d):
9292
# These are already stored in our DatetimeArray; if they are
9393
# also in the pickle and don't match, we have a problem.
9494
if key in d:
95-
assert d.pop(key) == getattr(dta, key)
95+
assert d[key] == getattr(dta, key)
96+
d.pop(key)
9697
result = cls._simple_new(dta, **d)
9798
else:
9899
with warnings.catch_warnings():

pandas/tests/test_downstream.py

+15
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ def test_oo_optimizable():
6969
subprocess.check_call([sys.executable, "-OO", "-c", "import pandas"])
7070

7171

72+
def test_oo_optimized_datetime_index_unpickle():
73+
# GH 42866
74+
subprocess.check_call(
75+
[
76+
sys.executable,
77+
"-OO",
78+
"-c",
79+
(
80+
"import pandas as pd, pickle; "
81+
"pickle.loads(pickle.dumps(pd.date_range('2021-01-01', periods=1)))"
82+
),
83+
]
84+
)
85+
86+
7287
@tm.network
7388
# Cython import warning
7489
@pytest.mark.filterwarnings("ignore:pandas.util.testing is deprecated")

0 commit comments

Comments
 (0)