Skip to content

Commit 14ab82e

Browse files
jbrockmendeljreback
authored andcommitted
CLN: remove unused legacy pickle compat code (#31078)
1 parent b2c90cc commit 14ab82e

File tree

3 files changed

+3
-55
lines changed

3 files changed

+3
-55
lines changed

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1928,9 +1928,9 @@ def __setstate__(self, state):
19281928
object.__setattr__(self, k, v)
19291929

19301930
else:
1931-
self._unpickle_series_compat(state)
1931+
raise NotImplementedError("Pre-0.12 pickles are no longer supported")
19321932
elif len(state) == 2:
1933-
self._unpickle_series_compat(state)
1933+
raise NotImplementedError("Pre-0.12 pickles are no longer supported")
19341934

19351935
self._item_cache = {}
19361936

pandas/core/internals/managers.py

+1-24
Original file line numberDiff line numberDiff line change
@@ -279,30 +279,7 @@ def unpickle_block(values, mgr_locs):
279279
unpickle_block(b["values"], b["mgr_locs"]) for b in state["blocks"]
280280
)
281281
else:
282-
# discard anything after 3rd, support beta pickling format for a
283-
# little while longer
284-
ax_arrays, bvalues, bitems = state[:3]
285-
286-
self.axes = [ensure_index(ax) for ax in ax_arrays]
287-
288-
if len(bitems) == 1 and self.axes[0].equals(bitems[0]):
289-
# This is a workaround for pre-0.14.1 pickles that didn't
290-
# support unpickling multi-block frames/panels with non-unique
291-
# columns/items, because given a manager with items ["a", "b",
292-
# "a"] there's no way of knowing which block's "a" is where.
293-
#
294-
# Single-block case can be supported under the assumption that
295-
# block items corresponded to manager items 1-to-1.
296-
all_mgr_locs = [slice(0, len(bitems[0]))]
297-
else:
298-
all_mgr_locs = [
299-
self.axes[0].get_indexer(blk_items) for blk_items in bitems
300-
]
301-
302-
self.blocks = tuple(
303-
unpickle_block(values, mgr_locs)
304-
for values, mgr_locs in zip(bvalues, all_mgr_locs)
305-
)
282+
raise NotImplementedError("pre-0.14.1 pickles are no longer supported")
306283

307284
self._post_setstate()
308285

pandas/core/series.py

-29
Original file line numberDiff line numberDiff line change
@@ -744,35 +744,6 @@ def __array__(self, dtype=None) -> np.ndarray:
744744

745745
# ----------------------------------------------------------------------
746746

747-
def _unpickle_series_compat(self, state) -> None:
748-
if isinstance(state, dict):
749-
self._data = state["_data"]
750-
self.name = state["name"]
751-
self.index = self._data.index
752-
753-
elif isinstance(state, tuple):
754-
755-
# < 0.12 series pickle
756-
757-
nd_state, own_state = state
758-
759-
# recreate the ndarray
760-
data = np.empty(nd_state[1], dtype=nd_state[2])
761-
np.ndarray.__setstate__(data, nd_state)
762-
763-
# backwards compat
764-
index, name = own_state[0], None
765-
if len(own_state) > 1:
766-
name = own_state[1]
767-
768-
# recreate
769-
self._data = SingleBlockManager(data, index, fastpath=True)
770-
self._index = index
771-
self.name = name
772-
773-
else:
774-
raise Exception(f"cannot unpickle legacy formats -> [{state}]")
775-
776747
# indexers
777748
@property
778749
def axes(self) -> List[Index]:

0 commit comments

Comments
 (0)