Skip to content

Commit ae84326

Browse files
tweak mro to get it working on python 3.14, fix refcount check for older python
1 parent 7d5a732 commit ae84326

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

pandas/_libs/internals.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ cdef inline bint _is_unique_referenced_temporary(object obj) except -1:
10221022
if PY_VERSION_HEX >= 0x030E0000:
10231023
return PyUnstable_Object_IsUniqueReferencedTemporary(obj)
10241024
else:
1025-
return sys.getrefcount(obj) == 2
1025+
return sys.getrefcount(obj) <= 1
10261026

10271027

10281028
# # Python version compatibility for PyUnstable_Object_IsUniqueReferencedTemporary
@@ -1038,6 +1038,7 @@ cdef inline bint _is_unique_referenced_temporary(object obj) except -1:
10381038
# return sys.getrefcount(obj) == 2
10391039

10401040

1041+
# @cython.auto_pickle(False)
10411042
cdef class SetitemMixin:
10421043

10431044
def __setitem__(self, key, value):
@@ -1052,3 +1053,6 @@ cdef class SetitemMixin:
10521053
stacklevel=1,
10531054
)
10541055
self._setitem(key, value)
1056+
1057+
def __delitem__(self, key) -> None:
1058+
self._delitem(key)

pandas/core/frame.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
properties,
4848
)
4949
from pandas._libs.hashtable import duplicated
50+
from pandas._libs.internals import SetitemMixin
5051
from pandas._libs.lib import is_range_indexer
5152
from pandas.compat import PYPY
5253
from pandas.compat._constants import REF_COUNT
@@ -510,7 +511,7 @@
510511

511512

512513
@set_module("pandas")
513-
class DataFrame(NDFrame, OpsMixin):
514+
class DataFrame(SetitemMixin, NDFrame, OpsMixin):
514515
"""
515516
Two-dimensional, size-mutable, potentially heterogeneous tabular data.
516517
@@ -659,6 +660,11 @@ class DataFrame(NDFrame, OpsMixin):
659660
# and ExtensionArray. Should NOT be overridden by subclasses.
660661
__pandas_priority__ = 4000
661662

663+
# override those to avoid inheriting from SetitemMixin (cython generates
664+
# them by default)
665+
__reduce__ = object.__reduce__
666+
__setstate__ = NDFrame.__setstate__
667+
662668
@property
663669
def _constructor(self) -> type[DataFrame]:
664670
return DataFrame

pandas/core/generic.py

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

2929
from pandas._libs import lib
30-
from pandas._libs.internals import SetitemMixin
3130
from pandas._libs.lib import is_range_indexer
3231
from pandas._libs.tslibs import (
3332
Period,
@@ -223,7 +222,7 @@
223222
}
224223

225224

226-
class NDFrame(PandasObject, indexing.IndexingMixin, SetitemMixin):
225+
class NDFrame(PandasObject, indexing.IndexingMixin):
227226
"""
228227
N-dimensional analogue of DataFrame. Store multi-dimensional in a
229228
size-mutable, labeled data structure
@@ -253,11 +252,6 @@ class NDFrame(PandasObject, indexing.IndexingMixin, SetitemMixin):
253252
# ----------------------------------------------------------------------
254253
# Constructors
255254

256-
# override those to avoid inheriting from SetitemMixin (cython generates
257-
# them by default)
258-
__new__ = object.__new__
259-
__reduce__ = object.__reduce__
260-
261255
def __init__(self, data: Manager) -> None:
262256
object.__setattr__(self, "_mgr", data)
263257
object.__setattr__(self, "_attrs", {})
@@ -4263,8 +4257,9 @@ def _slice(self, slobj: slice, axis: AxisInt = 0) -> Self:
42634257
result = result.__finalize__(self)
42644258
return result
42654259

4260+
# __delitem__ is implemented in SetitemMixin and dispatches to this method
42664261
@final
4267-
def __delitem__(self, key) -> None:
4262+
def _delitem(self, key) -> None:
42684263
"""
42694264
Delete item
42704265
"""

pandas/core/series.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
properties,
3333
reshape,
3434
)
35+
from pandas._libs.internals import SetitemMixin
3536
from pandas._libs.lib import is_range_indexer
3637
from pandas.compat import PYPY
3738
from pandas.compat._constants import REF_COUNT
@@ -233,7 +234,7 @@
233234
# class "NDFrame")
234235
# definition in base class "NDFrame"
235236
@set_module("pandas")
236-
class Series(base.IndexOpsMixin, NDFrame): # type: ignore[misc]
237+
class Series(SetitemMixin, base.IndexOpsMixin, NDFrame): # type: ignore[misc]
237238
"""
238239
One-dimensional ndarray with axis labels (including time series).
239240
@@ -361,6 +362,11 @@ class Series(base.IndexOpsMixin, NDFrame): # type: ignore[misc]
361362
)
362363
_mgr: SingleBlockManager
363364

365+
# override those to avoid inheriting from SetitemMixin (cython generates
366+
# them by default)
367+
__reduce__ = object.__reduce__
368+
__setstate__ = NDFrame.__setstate__
369+
364370
# ----------------------------------------------------------------------
365371
# Constructors
366372

0 commit comments

Comments
 (0)