Skip to content

Commit 7d5a732

Browse files
fix pickling
1 parent d66ab22 commit 7d5a732

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

pandas/compat/pickle_compat.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
PeriodArray,
2323
TimedeltaArray,
2424
)
25+
from pandas.core.generic import NDFrame
2526
from pandas.core.internals import BlockManager
2627

2728
if TYPE_CHECKING:
@@ -90,6 +91,10 @@ def load_reduce(self) -> None:
9091
cls = args[0]
9192
stack[-1] = NDArrayBacked.__new__(*args)
9293
return
94+
elif args and issubclass(args[0], NDFrame):
95+
cls = args[0]
96+
stack[-1] = cls.__new__(cls)
97+
return
9398
raise
9499

95100
dispatch[pickle.REDUCE[0]] = load_reduce # type: ignore[assignment]

pandas/core/frame.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
properties,
4848
)
4949
from pandas._libs.hashtable import duplicated
50-
from pandas._libs.internals import SetitemMixin
5150
from pandas._libs.lib import is_range_indexer
5251
from pandas.compat import PYPY
5352
from pandas.compat._constants import REF_COUNT
@@ -511,7 +510,7 @@
511510

512511

513512
@set_module("pandas")
514-
class DataFrame(NDFrame, OpsMixin, SetitemMixin):
513+
class DataFrame(NDFrame, OpsMixin):
515514
"""
516515
Two-dimensional, size-mutable, potentially heterogeneous tabular data.
517516

pandas/core/generic.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from pandas._config import config
2828

2929
from pandas._libs import lib
30+
from pandas._libs.internals import SetitemMixin
3031
from pandas._libs.lib import is_range_indexer
3132
from pandas._libs.tslibs import (
3233
Period,
@@ -222,7 +223,7 @@
222223
}
223224

224225

225-
class NDFrame(PandasObject, indexing.IndexingMixin):
226+
class NDFrame(PandasObject, indexing.IndexingMixin, SetitemMixin):
226227
"""
227228
N-dimensional analogue of DataFrame. Store multi-dimensional in a
228229
size-mutable, labeled data structure
@@ -252,6 +253,11 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
252253
# ----------------------------------------------------------------------
253254
# Constructors
254255

256+
# override those to avoid inheriting from SetitemMixin (cython generates
257+
# them by default)
258+
__new__ = object.__new__
259+
__reduce__ = object.__reduce__
260+
255261
def __init__(self, data: Manager) -> None:
256262
object.__setattr__(self, "_mgr", data)
257263
object.__setattr__(self, "_attrs", {})
@@ -305,7 +311,7 @@ def _from_mgr(cls, mgr: Manager, axes: list[Index]) -> Self:
305311
The axes must match mgr.axes, but are required for future-proofing
306312
in the event that axes are refactored out of the Manager objects.
307313
"""
308-
obj = object.__new__(cls)
314+
obj = cls.__new__(cls)
309315
NDFrame.__init__(obj, mgr)
310316
return obj
311317

pandas/core/series.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
properties,
3333
reshape,
3434
)
35-
from pandas._libs.internals import SetitemMixin
3635
from pandas._libs.lib import is_range_indexer
3736
from pandas.compat import PYPY
3837
from pandas.compat._constants import REF_COUNT
@@ -234,7 +233,7 @@
234233
# class "NDFrame")
235234
# definition in base class "NDFrame"
236235
@set_module("pandas")
237-
class Series(base.IndexOpsMixin, NDFrame, SetitemMixin): # type: ignore[misc]
236+
class Series(base.IndexOpsMixin, NDFrame): # type: ignore[misc]
238237
"""
239238
One-dimensional ndarray with axis labels (including time series).
240239

0 commit comments

Comments
 (0)