From 109ae0246f916caecb16321255aa0337b2fbfd7f Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 12 Apr 2023 18:33:14 -0700 Subject: [PATCH 01/10] Remove old pickle compat --- pandas/compat/pickle_compat.py | 17 ----------------- pandas/core/arrays/sparse/array.py | 17 ----------------- pandas/core/internals/managers.py | 5 ----- 3 files changed, 39 deletions(-) diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index 9800c960f031b..2fdaaed0fcf77 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -59,23 +59,6 @@ def load_reduce(self): # If classes are moved, provide compat here. _class_locations_map = { - ("pandas.core.sparse.array", "SparseArray"): ("pandas.core.arrays", "SparseArray"), - # 15477 - ("pandas.core.base", "FrozenNDArray"): ("numpy", "ndarray"), - ("pandas.core.indexes.frozen", "FrozenNDArray"): ("numpy", "ndarray"), - ("pandas.core.base", "FrozenList"): ("pandas.core.indexes.frozen", "FrozenList"), - # 10890 - ("pandas.core.series", "TimeSeries"): ("pandas.core.series", "Series"), - ("pandas.sparse.series", "SparseTimeSeries"): ( - "pandas.core.sparse.series", - "SparseSeries", - ), - # 12588, extensions moving - ("pandas._sparse", "BlockIndex"): ("pandas._libs.sparse", "BlockIndex"), - ("pandas.tslib", "Timestamp"): ("pandas._libs.tslib", "Timestamp"), - # 18543 moving period - ("pandas._period", "Period"): ("pandas._libs.tslibs.period", "Period"), - ("pandas._libs.period", "Period"): ("pandas._libs.tslibs.period", "Period"), # 18014 moved __nat_unpickle from _libs.tslib-->_libs.tslibs.nattype ("pandas.tslib", "__nat_unpickle"): ( "pandas._libs.tslibs.nattype", diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index f78486fa7d84f..08838535eac90 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -1342,23 +1342,6 @@ def _where(self, mask, value): result = type(self)._from_sequence(naive_implementation, dtype=dtype) return result - # ------------------------------------------------------------------------ - # IO - # ------------------------------------------------------------------------ - def __setstate__(self, state) -> None: - """Necessary for making this object picklable""" - if isinstance(state, tuple): - # Compat for pandas < 0.24.0 - nd_state, (fill_value, sp_index) = state - sparse_values = np.array([]) - sparse_values.__setstate__(nd_state) - - self._sparse_values = sparse_values - self._sparse_index = sp_index - self._dtype = SparseDtype(sparse_values.dtype, fill_value) - else: - self.__dict__.update(state) - def nonzero(self) -> tuple[npt.NDArray[np.int32]]: if self.fill_value == 0: return (self.sp_index.indices,) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index ff637695a4816..e7715fab617cb 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1953,11 +1953,6 @@ def unpickle_block(values, mgr_locs, ndim: int) -> Block: else: raise NotImplementedError("pre-0.14.1 pickles are no longer supported") - self._post_setstate() - - def _post_setstate(self) -> None: - pass - @cache_readonly def _block(self) -> Block: return self.blocks[0] From 0613b0e400bafb934113f17283637c250da6fd80 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 13 Apr 2023 09:32:32 -0700 Subject: [PATCH 02/10] more pickle cleanup --- pandas/compat/pickle_compat.py | 55 ++-------------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index 2fdaaed0fcf77..e689c963b7b48 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -1,5 +1,5 @@ """ -Support pre-0.12 series pickle compatibility. +Pickle compatibility. """ from __future__ import annotations @@ -59,52 +59,7 @@ def load_reduce(self): # If classes are moved, provide compat here. _class_locations_map = { - # 18014 moved __nat_unpickle from _libs.tslib-->_libs.tslibs.nattype - ("pandas.tslib", "__nat_unpickle"): ( - "pandas._libs.tslibs.nattype", - "__nat_unpickle", - ), - ("pandas._libs.tslib", "__nat_unpickle"): ( - "pandas._libs.tslibs.nattype", - "__nat_unpickle", - ), - # 15998 top-level dirs moving - ("pandas.sparse.array", "SparseArray"): ( - "pandas.core.arrays.sparse", - "SparseArray", - ), - ("pandas.indexes.base", "_new_Index"): ("pandas.core.indexes.base", "_new_Index"), - ("pandas.indexes.base", "Index"): ("pandas.core.indexes.base", "Index"), - ("pandas.indexes.numeric", "Int64Index"): ( - "pandas.core.indexes.base", - "Index", # updated in 50775 - ), - ("pandas.indexes.range", "RangeIndex"): ("pandas.core.indexes.range", "RangeIndex"), - ("pandas.indexes.multi", "MultiIndex"): ("pandas.core.indexes.multi", "MultiIndex"), - ("pandas.tseries.index", "_new_DatetimeIndex"): ( - "pandas.core.indexes.datetimes", - "_new_DatetimeIndex", - ), - ("pandas.tseries.index", "DatetimeIndex"): ( - "pandas.core.indexes.datetimes", - "DatetimeIndex", - ), - ("pandas.tseries.period", "PeriodIndex"): ( - "pandas.core.indexes.period", - "PeriodIndex", - ), - # 19269, arrays moving - ("pandas.core.categorical", "Categorical"): ("pandas.core.arrays", "Categorical"), - # 19939, add timedeltaindex, float64index compat from 15998 move - ("pandas.tseries.tdi", "TimedeltaIndex"): ( - "pandas.core.indexes.timedeltas", - "TimedeltaIndex", - ), - ("pandas.indexes.numeric", "Float64Index"): ( - "pandas.core.indexes.base", - "Index", # updated in 50775 - ), - # 50775, remove Int64Index, UInt64Index & Float64Index from codabase + # 50775, remove Int64Index, UInt64Index & Float64Index from codebase ("pandas.core.indexes.numeric", "Int64Index"): ( "pandas.core.indexes.base", "Index", @@ -179,7 +134,7 @@ def load_newobj_ex(self) -> None: pass -def load(fh, encoding: str | None = None, is_verbose: bool = False): +def load(fh, encoding: str | None = None): """ Load a pickle, with a provided encoding, @@ -187,7 +142,6 @@ def load(fh, encoding: str | None = None, is_verbose: bool = False): ---------- fh : a filelike object encoding : an optional encoding - is_verbose : show exception output """ try: fh.seek(0) @@ -195,9 +149,6 @@ def load(fh, encoding: str | None = None, is_verbose: bool = False): up = Unpickler(fh, encoding=encoding) else: up = Unpickler(fh) - # "Unpickler" has no attribute "is_verbose" [attr-defined] - up.is_verbose = is_verbose # type: ignore[attr-defined] - return up.load() except (ValueError, TypeError): raise From ab12e0526dc72d45f1187d8d3ae02ed8e1f70dce Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 13 Apr 2023 13:40:11 -0700 Subject: [PATCH 03/10] Remove pre-1.0 pickle compat --- pandas/compat/pickle_compat.py | 115 ++++++++++++--------------------- 1 file changed, 41 insertions(+), 74 deletions(-) diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index e689c963b7b48..5b65cea33a623 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -6,7 +6,7 @@ import contextlib import copy import io -import pickle as pkl +import pickle from typing import Generator import numpy as np @@ -14,7 +14,6 @@ from pandas._libs.arrays import NDArrayBacked from pandas._libs.tslibs import BaseOffset -from pandas import Index from pandas.core.arrays import ( DatetimeArray, PeriodArray, @@ -22,41 +21,6 @@ ) from pandas.core.internals import BlockManager - -def load_reduce(self): - stack = self.stack - args = stack.pop() - func = stack[-1] - - try: - stack[-1] = func(*args) - return - except TypeError as err: - # If we have a deprecated function, - # try to replace and try again. - - msg = "_reconstruct: First argument must be a sub-type of ndarray" - - if msg in str(err): - try: - cls = args[0] - stack[-1] = object.__new__(cls) - return - except TypeError: - pass - elif args and isinstance(args[0], type) and issubclass(args[0], BaseOffset): - # TypeError: object.__new__(Day) is not safe, use Day.__new__() - cls = args[0] - stack[-1] = cls.__new__(*args) - return - elif args and issubclass(args[0], PeriodArray): - cls = args[0] - stack[-1] = NDArrayBacked.__new__(*args) - return - - raise - - # If classes are moved, provide compat here. _class_locations_map = { # 50775, remove Int64Index, UInt64Index & Float64Index from codebase @@ -79,7 +43,7 @@ def load_reduce(self): # functions for compat and uses a non-public class of the pickle module. -class Unpickler(pkl._Unpickler): +class Unpickler(pickle.Unpickler): def find_class(self, module, name): # override superclass key = (module, name) @@ -88,7 +52,34 @@ def find_class(self, module, name): Unpickler.dispatch = copy.copy(Unpickler.dispatch) -Unpickler.dispatch[pkl.REDUCE[0]] = load_reduce + + +def load_reduce(self): + stack = self.stack + args = stack.pop() + func = stack[-1] + + try: + stack[-1] = func(*args) + return + except TypeError: + # If we have a deprecated function, + # try to replace and try again. + + if args and isinstance(args[0], type) and issubclass(args[0], BaseOffset): + # TypeError: object.__new__(Day) is not safe, use Day.__new__() + cls = args[0] + stack[-1] = cls.__new__(*args) + return + elif args and issubclass(args[0], PeriodArray): + cls = args[0] + stack[-1] = NDArrayBacked.__new__(*args) + return + + raise + + +Unpickler.dispatch[pickle.REDUCE[0]] = load_reduce def load_newobj(self) -> None: @@ -96,9 +87,7 @@ def load_newobj(self) -> None: cls = self.stack[-1] # compat - if issubclass(cls, Index): - obj = object.__new__(cls) - elif issubclass(cls, DatetimeArray) and not args: + if issubclass(cls, DatetimeArray) and not args: arr = np.array([], dtype="M8[ns]") obj = cls.__new__(cls, arr, arr.dtype) elif issubclass(cls, TimedeltaArray) and not args: @@ -112,26 +101,7 @@ def load_newobj(self) -> None: self.stack[-1] = obj -Unpickler.dispatch[pkl.NEWOBJ[0]] = load_newobj - - -def load_newobj_ex(self) -> None: - kwargs = self.stack.pop() - args = self.stack.pop() - cls = self.stack.pop() - - # compat - if issubclass(cls, Index): - obj = object.__new__(cls) - else: - obj = cls.__new__(cls, *args, **kwargs) - self.append(obj) - - -try: - Unpickler.dispatch[pkl.NEWOBJ_EX[0]] = load_newobj_ex -except (AttributeError, KeyError): - pass +Unpickler.dispatch[pickle.NEWOBJ[0]] = load_newobj def load(fh, encoding: str | None = None): @@ -143,15 +113,12 @@ def load(fh, encoding: str | None = None): fh : a filelike object encoding : an optional encoding """ - try: - fh.seek(0) - if encoding is not None: - up = Unpickler(fh, encoding=encoding) - else: - up = Unpickler(fh) - return up.load() - except (ValueError, TypeError): - raise + fh.seek(0) + if encoding is not None: + up = Unpickler(fh, encoding=encoding) + else: + up = Unpickler(fh) + return up.load() def loads( @@ -175,9 +142,9 @@ def patch_pickle() -> Generator[None, None, None]: """ Temporarily patch pickle to use our unpickler. """ - orig_loads = pkl.loads + orig_loads = pickle.loads try: - setattr(pkl, "loads", loads) + setattr(pickle, "loads", loads) yield finally: - setattr(pkl, "loads", orig_loads) + setattr(pickle, "loads", orig_loads) From ae6a7325709a7a38e2fbd5d4f2b7f412f0cf4af9 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 13 Apr 2023 13:40:35 -0700 Subject: [PATCH 04/10] add note about compat version --- pandas/compat/pickle_compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index 5b65cea33a623..e26bc73e758f7 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -1,5 +1,5 @@ """ -Pickle compatibility. +Pickle compatibility to pandas version 1.0 """ from __future__ import annotations From 93d5d5fa235b04787f79d73477c2b52cb66043a4 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 31 Jul 2023 13:22:09 -0700 Subject: [PATCH 05/10] Fix note --- pandas/io/pickle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index de9f1168e40dd..bda149447539d 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -159,7 +159,7 @@ def read_pickle( Notes ----- - read_pickle is only guaranteed to be backwards compatible to pandas 0.20.3 + read_pickle is only guaranteed to be backwards compatible to pandas 1.0.0 provided the object was serialized with to_pickle. Examples From fe250ebb1ad6ff1cca904405bc6b80133e5f6462 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 28 Aug 2023 09:07:08 -0700 Subject: [PATCH 06/10] Change compat function --- pandas/_libs/tslibs/nattype.pyx | 4 ++-- pandas/compat/pickle_compat.py | 31 +++++++++++-------------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 7d75fa3114d2b..41492f3c8ea90 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -80,7 +80,7 @@ cdef _nat_rdivide_op(self, other): return NotImplemented -def __nat_unpickle(*args): +def _nat_unpickle(*args): # return constant defined in the module return c_NaT @@ -387,7 +387,7 @@ class NaTType(_NaT): return self.__reduce__() def __reduce__(self): - return (__nat_unpickle, (None, )) + return (_nat_unpickle, (None, )) def __rtruediv__(self, other): return _nat_rdivide_op(self, other) diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index 9bdee386c166d..7226330bcea3b 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -4,7 +4,7 @@ from __future__ import annotations import contextlib -import copy +import copyreg import io import pickle from typing import TYPE_CHECKING @@ -47,21 +47,6 @@ } -# our Unpickler sub-class to override methods and some dispatcher -# functions for compat and uses a non-public class of the pickle module. - - -class Unpickler(pickle.Unpickler): - def find_class(self, module, name): - # override superclass - key = (module, name) - module, name = _class_locations_map.get(key, key) - return super().find_class(module, name) - - -Unpickler.dispatch = copy.copy(Unpickler.dispatch) - - def load_reduce(self): stack = self.stack args = stack.pop() @@ -87,9 +72,6 @@ def load_reduce(self): raise -Unpickler.dispatch[pickle.REDUCE[0]] = load_reduce - - def load_newobj(self) -> None: args = self.stack.pop() cls = self.stack[-1] @@ -109,7 +91,16 @@ def load_newobj(self) -> None: self.stack[-1] = obj -Unpickler.dispatch[pickle.NEWOBJ[0]] = load_newobj +class Unpickler(pickle.Unpickler): + dispatch_table = copyreg.dispatch_table.copy() + dispatch_table[pickle.REDUCE[0]] = load_reduce + dispatch_table[pickle.NEWOBJ[0]] = load_newobj + + def find_class(self, module, name): + # override superclass + key = (module, name) + module, name = _class_locations_map.get(key, key) + return super().find_class(module, name) def load(fh, encoding: str | None = None): From e58347888cc24ae80dc8413cea4e968be6d957bb Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:07:31 -0800 Subject: [PATCH 07/10] Add whatsnew --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 6d41c29a6c614..9422a4c3fdfc8 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -85,7 +85,7 @@ See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for mor Other API changes ^^^^^^^^^^^^^^^^^ - 3rd party ``py.path`` objects are no longer explicitly supported in IO methods. Use :py:class:`pathlib.Path` objects instead (:issue:`57091`) -- +- pickled objects from pandas version less than ``1.0.0`` are no longer supported (:issue:`?`) .. --------------------------------------------------------------------------- .. _whatsnew_300.deprecations: From c6415fd8707d77fb3e5a084375b11e5bc9bbe67e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:11:07 -0800 Subject: [PATCH 08/10] Add number --- doc/source/whatsnew/v3.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 9422a4c3fdfc8..0e5a51e0ba72a 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -85,7 +85,7 @@ See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for mor Other API changes ^^^^^^^^^^^^^^^^^ - 3rd party ``py.path`` objects are no longer explicitly supported in IO methods. Use :py:class:`pathlib.Path` objects instead (:issue:`57091`) -- pickled objects from pandas version less than ``1.0.0`` are no longer supported (:issue:`?`) +- pickled objects from pandas version less than ``1.0.0`` are no longer supported (:issue:`57155`) .. --------------------------------------------------------------------------- .. _whatsnew_300.deprecations: From 49d0613dd9a8a24c7a95fa30fdac58d64199788b Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:57:24 -0800 Subject: [PATCH 09/10] Remove old pickles --- ...periodindex_0.20.1_x86_64_darwin_2.7.13.h5 | Bin 7312 -> 0 bytes .../io/data/pickle/categorical.0.25.0.pickle | Bin 578 -> 0 bytes pandas/tests/io/data/pickle/test_mi_py27.pkl | Bin 1395 -> 0 bytes pandas/tests/io/pytables/test_read.py | 28 ------------------ 4 files changed, 28 deletions(-) delete mode 100644 pandas/tests/io/data/legacy_hdf/periodindex_0.20.1_x86_64_darwin_2.7.13.h5 delete mode 100644 pandas/tests/io/data/pickle/categorical.0.25.0.pickle delete mode 100644 pandas/tests/io/data/pickle/test_mi_py27.pkl diff --git a/pandas/tests/io/data/legacy_hdf/periodindex_0.20.1_x86_64_darwin_2.7.13.h5 b/pandas/tests/io/data/legacy_hdf/periodindex_0.20.1_x86_64_darwin_2.7.13.h5 deleted file mode 100644 index 6fb92d3c564bdfc290313ab4ef0ca63e1574711e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7312 zcmeGgL2}zhY-u|Qvr$r|Z91Jy558HKY9!Zb(^IU}a;+KH@<>X?KG8I__OO;nmP@5^ zUy$DVj2`=h9CPVR9*}l=%rQSmfnC5o?_HDe!S! zu^_6Z%gtMQe)-H|c+B&A)Nu$tBlzo_?KtA9z`0KeU#0aI=Plwj;Rn5TTL2}m&yc3Y zi>tQhGGYcVl?FE2t!;ea9eQiF(idcBtc-*@Y>yi}@ju~hve%+rS47RMi1zKm-=H(t z1OpZy!4GA#d_x3Hk^Y;_R=*E;q`v|`rvJ9reS|NX)8p!{c--#wJKZfqkFLY?&3Xey zNPpiz2Rseww|57vhnwxbx8Ci2*BW?b{LA$w@m0;5ML(^Q!#yW~|K_KE*+_EY?`H8? zb7?eC^iyk#lca-d*Y8KO6TJ+Q)3*S*!v<5&UpG;-8BcO z$XtcHV2RjI8Z_Q6?Bk53E;WkJ=jt7+28>1c@*sNW1PXbYHfAZ5HcShXF1<3BhUB?xJMeQ>=-yu-Zl6!U#bo#BR_@lO^c%m zJP+`39E)IjhWx#29~(09+5$L}T(i#H+?*kGVIAzuJGF`>VNbK859w`?=G7;Uc8m5> zcHXsmz1A-9%PKcM+4O?kbrI|gl|1!cF zP5gGZjKbpiJblic^T{v#?5of17XKjlCqavS^MGDp)k2pbVP{~bftdzo8klKdrh%CT z-YE^t!#xP*cE!9k&)cqIEZTYh%S|m(%rRqS7!1 zi>-(^X5KNCmMacY^#dZ1{&)DX-3LLO9D7jRNoayN(pfqQvN)AVQ`Q1o_0}^Dt14ZO z4-T}-w0t)P9k52!|56)QKy%3C5V_q&am-HB6S$yBbGmQLtNt}fIg=aRS87F?ipZ(i@g<$l5*+4PY z2C=+~au2Db7!Q)X(QFlfjl3>nO-X#ggEYyc$OB0*QK*ROMZX6GlaA5BRMljd?qbHp ztmT+arGvSFPy-UodnI+z{S_7*!!f&9bg^VPWzSUAS1i|RwYyI>^yFMitgzk#RxQ0x zv8E%#x{d)hbPTb{CAOGmNN9s&yOw`o$HlHUqI^>ka=}CF^}Hpu^apGIQKSt&)KX{h>p5KTlH>M&A7M=p*BL{?Nl#FscJAWmJJDTwIL^9_k})~i+wvsA`~ Jgw1khe*xOWy9xjR diff --git a/pandas/tests/io/data/pickle/test_mi_py27.pkl b/pandas/tests/io/data/pickle/test_mi_py27.pkl deleted file mode 100644 index 89021dd82810861dbfeef234dea91197396e20b8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1395 zcmZ`(Z)_Ar6u-T@p6!;Z6PwD7TRsEv2h?Ktee@rxtj}jd-wJa zQspX|v;t~k1mZV8_@U9n1S9GfW459J8?Eu1HYO^XXdpEYX6 ziP3#UVrvyxC$Z{9@oMLn|V&Pu?$ zDXz0}rkyhr)C9?M*7-jiO=6^|I9^*H@MqGxslCR_HOb-z6JL`Q1PB3c=Yd~EeyMwgCEb}A=6M=wq{M$qYbwD z7k-*N?>3ybM|Pk1#a(;!LgKA6pSj!S-yR$2o^T%{Soc!b<JE34+1007t#D! zQ*UtYXSapDa_Z&QbMDUB*V)O>$rEL==} z>FkD;ofl}YP-_GLagA#d_WaAY6JINZ-D Ni#f!xY|YW4{{SjH`hoxe diff --git a/pandas/tests/io/pytables/test_read.py b/pandas/tests/io/pytables/test_read.py index c8563ee4af4a8..0fd0a8774bbf4 100644 --- a/pandas/tests/io/pytables/test_read.py +++ b/pandas/tests/io/pytables/test_read.py @@ -348,34 +348,6 @@ def test_read_hdf_series_mode_r(tmp_path, format, setup_path): tm.assert_series_equal(result, series) -@pytest.mark.filterwarnings(r"ignore:Period with BDay freq is deprecated:FutureWarning") -@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning") -def test_read_py2_hdf_file_in_py3(datapath): - # GH 16781 - - # tests reading a PeriodIndex DataFrame written in Python2 in Python3 - - # the file was generated in Python 2.7 like so: - # - # df = DataFrame([1.,2,3], index=pd.PeriodIndex( - # ['2015-01-01', '2015-01-02', '2015-01-05'], freq='B')) - # df.to_hdf('periodindex_0.20.1_x86_64_darwin_2.7.13.h5', 'p') - - expected = DataFrame( - [1.0, 2, 3], - index=pd.PeriodIndex(["2015-01-01", "2015-01-02", "2015-01-05"], freq="B"), - ) - - with ensure_clean_store( - datapath( - "io", "data", "legacy_hdf", "periodindex_0.20.1_x86_64_darwin_2.7.13.h5" - ), - mode="r", - ) as store: - result = store["p"] - tm.assert_frame_equal(result, expected) - - def test_read_infer_string(tmp_path, setup_path): # GH#54431 pytest.importorskip("pyarrow") From 05feac6f2da416ecb982521544e2be889bea6dcd Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:52:38 -0800 Subject: [PATCH 10/10] fix tests, remove 27 files --- doc/source/whatsnew/v3.0.0.rst | 2 +- pandas/compat/pickle_compat.py | 5 ++++- pandas/tests/io/data/pickle/test_py27.pkl | Bin 943 -> 0 bytes pandas/tests/io/test_common.py | 15 ++++++++----- pandas/tests/io/test_pickle.py | 25 ---------------------- 5 files changed, 15 insertions(+), 32 deletions(-) delete mode 100644 pandas/tests/io/data/pickle/test_py27.pkl diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 2c8177428e41b..a6d9e079b26fe 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -85,7 +85,7 @@ See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for mor Other API changes ^^^^^^^^^^^^^^^^^ - 3rd party ``py.path`` objects are no longer explicitly supported in IO methods. Use :py:class:`pathlib.Path` objects instead (:issue:`57091`) -- pickled objects from pandas version less than ``1.0.0`` are no longer supported (:issue:`57155`) +- pickled objects from pandas version less than ``1.0.0`` or Python versions less than or equal to ``2.7`` are no longer supported (:issue:`57155`) .. --------------------------------------------------------------------------- .. _whatsnew_300.deprecations: diff --git a/pandas/compat/pickle_compat.py b/pandas/compat/pickle_compat.py index f72fb61dbcb11..012a53789d76a 100644 --- a/pandas/compat/pickle_compat.py +++ b/pandas/compat/pickle_compat.py @@ -36,6 +36,10 @@ "pandas._libs.internals", "_unpickle_block", ), + ("pandas._libs.tslibs.nattype", "__nat_unpickle"): ( + "pandas._libs.tslibs.nattype", + "_nat_unpickle", + ), # 50775, remove Int64Index, UInt64Index & Float64Index from codebase ("pandas.core.indexes.numeric", "Int64Index"): ( "pandas.core.indexes.base", @@ -106,7 +110,6 @@ class Unpickler(pickle.Unpickler): dispatch_table[pickle.NEWOBJ[0]] = load_newobj def find_class(self, module, name): - # override superclass key = (module, name) module, name = _class_locations_map.get(key, key) return super().find_class(module, name) diff --git a/pandas/tests/io/data/pickle/test_py27.pkl b/pandas/tests/io/data/pickle/test_py27.pkl deleted file mode 100644 index 5308b864bc0c728db604bac7b5007c1c0c916e4a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 943 zcmZ`%Ye*DP6yBGnCWuvZ0(MF=b>%5pv9W@ zqaV>jg4zh`Ps&0>7A7M}Yy{F9N-fH==p9jrf2!;3Mr_pmak%%K@0|OcbG~Mq5Ja*U zsfkAaXy`D>WDBw$2!;|326VsXLyCez6sL$ny{u}AE@%|aNuVe)3p0vy zSxW?3`9n2$D$QD1dn5_)lD0((PlLAVwXB7;62NqtwL@!@+wHFUNseh)pz-YX@7L9L%U(PnRRE#`)2FkSS z)8{NTOM#_Hm#_4C_?z;2i8b)WB}vF?4e{N$0# zAhsbtTJre2F?_YEzqi`b2V+x*kH5HUoIllB%{={R+-XAbXnP;n7r*Z}P#g>oI(Odw zI%>IL9bm={EKPb)H<%F&8z}OXA&q(_iIJd^zxh+0mTs+v4 zUH;$=c$sbMJ^i>J#P_e