From 3252f1e72a3793fce5af422b8d2739de587860d7 Mon Sep 17 00:00:00 2001 From: GorAlexander Date: Tue, 3 Aug 2021 20:31:50 +0300 Subject: [PATCH 1/7] BUG: GH42866 DatetimeIndex de-serializing fails in PYTHONOPTIMIZE mode --- pandas/core/indexes/datetimes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 9712a5d95a234..b39ff486e91a7 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -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(): From a9c3396328551717ebaecd961d443a07dc6abe51 Mon Sep 17 00:00:00 2001 From: GorAlexander Date: Wed, 4 Aug 2021 01:58:26 +0300 Subject: [PATCH 2/7] BUG: GH42866 DatetimeIndex de-serializing fails in PYTHONOPTIMIZE mode --- pandas/tests/test_downstream.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index 6a7d64235f11c..4926c19be1bae 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -73,6 +73,14 @@ 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") From e0162ef942f5fa5f6c928086235347a6dfa4ef2d Mon Sep 17 00:00:00 2001 From: GorAlexander Date: Wed, 4 Aug 2021 02:06:42 +0300 Subject: [PATCH 3/7] BUG: GH42866 DatetimeIndex de-serializing fails in PYTHONOPTIMIZE mode [fix pep8] --- pandas/tests/test_downstream.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index 4926c19be1bae..2fdd2b6372b6e 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -77,7 +77,10 @@ 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)))", + ( + "import pandas as pd, pickle; " + "pickle.loads(pickle.dumps(pd.date_range('2021-01-01', periods=1)))" + ), ]) From 0e62243cd8883413b7bab4776e2210a588eed3ba Mon Sep 17 00:00:00 2001 From: GorAlexander Date: Wed, 4 Aug 2021 12:53:38 +0300 Subject: [PATCH 4/7] BUG: GH42866 DatetimeIndex de-serializing fails in PYTHONOPTIMIZE mode [fix pre-commit check] --- pandas/tests/test_downstream.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index 2fdd2b6372b6e..80fbe809099a9 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -75,13 +75,17 @@ def test_oo_optimizable(): 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)))" - ), - ]) + 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 From 5fea15d9f0a5ee4a63d4739d42c23ec1e8a70b60 Mon Sep 17 00:00:00 2001 From: GorAlexander Date: Wed, 4 Aug 2021 15:21:09 +0300 Subject: [PATCH 5/7] BUG: GH42866 DatetimeIndex de-serializing fails in PYTHONOPTIMIZE mode [add whatsnew] --- doc/source/whatsnew/v1.4.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index ad6a9d994bf7b..a11d031790cba 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -193,6 +193,7 @@ Categorical Datetimelike ^^^^^^^^^^^^ - Bug in :class:`DataFrame` constructor unnecessarily copying non-datetimelike 2D object arrays (:issue:`39272`) +- Bug in :func:`_new_DatetimeIndex` when de-serializing datetime indexes in PYTHONOPTIMIZED mode (:issue:`42866`) - Timedelta From 4a4658bc59612a192561500ee53de55eb4af348e Mon Sep 17 00:00:00 2001 From: GorAlexander Date: Wed, 4 Aug 2021 16:01:48 +0300 Subject: [PATCH 6/7] BUG: GH42866 DatetimeIndex de-serializing fails in PYTHONOPTIMIZE mode [add whatsnew to v1.3.2] --- doc/source/whatsnew/v1.3.2.rst | 1 + doc/source/whatsnew/v1.4.0.rst | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.2.rst b/doc/source/whatsnew/v1.3.2.rst index 8723b1b766485..fcbcd9411beb7 100644 --- a/doc/source/whatsnew/v1.3.2.rst +++ b/doc/source/whatsnew/v1.3.2.rst @@ -31,6 +31,7 @@ Fixed regressions Bug fixes ~~~~~~~~~ - 1D slices over extension types turn into N-dimensional slices over ExtensionArrays (:issue:`42430`) +- Bug in :func:`_new_DatetimeIndex` when de-serializing datetime indexes in PYTHONOPTIMIZED mode (:issue:`42866`) - .. --------------------------------------------------------------------------- diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index a11d031790cba..ad6a9d994bf7b 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -193,7 +193,6 @@ Categorical Datetimelike ^^^^^^^^^^^^ - Bug in :class:`DataFrame` constructor unnecessarily copying non-datetimelike 2D object arrays (:issue:`39272`) -- Bug in :func:`_new_DatetimeIndex` when de-serializing datetime indexes in PYTHONOPTIMIZED mode (:issue:`42866`) - Timedelta From c6f526489e76a8e011bb900dec8b0b4da3c89f0f Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Wed, 4 Aug 2021 17:56:31 -0400 Subject: [PATCH 7/7] Update doc/source/whatsnew/v1.3.2.rst --- doc/source/whatsnew/v1.3.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.2.rst b/doc/source/whatsnew/v1.3.2.rst index 5fa4571629f61..7a310115b194e 100644 --- a/doc/source/whatsnew/v1.3.2.rst +++ b/doc/source/whatsnew/v1.3.2.rst @@ -32,7 +32,7 @@ Bug fixes ~~~~~~~~~ - 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 :func:`_new_DatetimeIndex` when de-serializing datetime indexes in PYTHONOPTIMIZED mode (:issue:`42866`) +- Bug in de-serializing datetime indexes in PYTHONOPTIMIZED mode (:issue:`42866`) - .. ---------------------------------------------------------------------------