Skip to content

Commit 66cd359

Browse files
cleanup
1 parent 622efa5 commit 66cd359

File tree

4 files changed

+12
-39
lines changed

4 files changed

+12
-39
lines changed

pandas/_libs/internals.pyx

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ cnp.import_array()
2424

2525
from pandas._libs.algos import ensure_int64
2626
from pandas.errors import ChainedAssignmentError
27+
from pandas.errors.cow import _chained_assignment_msg
28+
2729

2830
from pandas._libs.util cimport (
2931
is_array,
@@ -1005,10 +1007,7 @@ cdef class BlockValuesRefs:
10051007
cdef extern from "Python.h":
10061008
"""
10071009
#if PY_VERSION_HEX < 0x030E0000
1008-
int __Pyx_PyUnstable_Object_IsUniqueReferencedTemporary(PyObject *ref)
1009-
{
1010-
return 0;
1011-
}
1010+
int __Pyx_PyUnstable_Object_IsUniqueReferencedTemporary(PyObject *ref);
10121011
#else
10131012
#define __Pyx_PyUnstable_Object_IsUniqueReferencedTemporary \
10141013
PyUnstable_Object_IsUniqueReferencedTemporary
@@ -1018,40 +1017,25 @@ cdef extern from "Python.h":
10181017
"__Pyx_PyUnstable_Object_IsUniqueReferencedTemporary"(object o) except -1
10191018

10201019

1020+
# Python version compatibility for PyUnstable_Object_IsUniqueReferencedTemporary
10211021
cdef inline bint _is_unique_referenced_temporary(object obj) except -1:
10221022
if PY_VERSION_HEX >= 0x030E0000:
1023+
# Python 3.14+ has PyUnstable_Object_IsUniqueReferencedTemporary
10231024
return PyUnstable_Object_IsUniqueReferencedTemporary(obj)
10241025
else:
1026+
# Fallback for older Python versions using sys.getrefcount
10251027
return sys.getrefcount(obj) <= 1
10261028

10271029

1028-
# # Python version compatibility for PyUnstable_Object_IsUniqueReferencedTemporary
1029-
# IF PY_VERSION_HEX >= 0x030E0000:
1030-
# # Python 3.14+ has PyUnstable_Object_IsUniqueReferencedTemporary
1031-
# cdef inline bint _is_unique_referenced_temporary(object obj) except -1:
1032-
# return PyUnstable_Object_IsUniqueReferencedTemporary(obj)
1033-
# ELSE:
1034-
# # Fallback for older Python versions using sys.getrefcount
1035-
# cdef inline bint _is_unique_referenced_temporary(object obj) except -1:
1036-
# # sys.getrefcount includes the reference from getrefcount itself
1037-
# # So if refcount is 2, it means only one external reference exists
1038-
# return sys.getrefcount(obj) == 2
1039-
1040-
1041-
# @cython.auto_pickle(False)
10421030
cdef class SetitemMixin:
1031+
# class used in DataFrame and Series for checking for chained assignment
10431032

1044-
def __setitem__(self, key, value):
1033+
def __setitem__(self, key, value) -> None:
10451034
cdef bint is_unique = _is_unique_referenced_temporary(self)
1046-
# print("Refcount self: ", sys.getrefcount(self))
1047-
# print("Is unique referenced temporary: ", is_unique)
10481035
if is_unique:
10491036
warnings.warn(
1050-
"A value is trying to be set on a copy of a DataFrame or Series "
1051-
"through chained assignment.",
1052-
ChainedAssignmentError,
1053-
stacklevel=1,
1054-
)
1037+
_chained_assignment_msg, ChainedAssignmentError, stacklevel=1
1038+
)
10551039
self._setitem(key, value)
10561040

10571041
def __delitem__(self, key) -> None:

pandas/core/frame.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4218,6 +4218,7 @@ def isetitem(self, loc, value) -> None:
42184218
arraylike, refs = self._sanitize_column(value)
42194219
self._iset_item_mgr(loc, arraylike, inplace=False, refs=refs)
42204220

4221+
# def __setitem__() is implemented in SetitemMixin and dispatches to this method
42214222
def _setitem(self, key, value) -> None:
42224223
"""
42234224
Set item(s) in DataFrame by key.
@@ -4302,12 +4303,6 @@ def _setitem(self, key, value) -> None:
43024303
z 3 50
43034304
# Values for 'a' and 'b' are completely ignored!
43044305
"""
4305-
# if not PYPY:
4306-
# if sys.getrefcount(self) <= 3:
4307-
# warnings.warn(
4308-
# _chained_assignment_msg, ChainedAssignmentError, stacklevel=2
4309-
# )
4310-
43114306
key = com.apply_if_callable(key, self)
43124307

43134308
# see if we can slice the rows

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4258,7 +4258,7 @@ def _slice(self, slobj: slice, axis: AxisInt = 0) -> Self:
42584258
result = result.__finalize__(self)
42594259
return result
42604260

4261-
# __delitem__ is implemented in SetitemMixin and dispatches to this method
4261+
# def __delitem__() is implemented in SetitemMixin and dispatches to this method
42624262
@final
42634263
def _delitem(self, key) -> None:
42644264
"""

pandas/core/series.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,12 +1065,6 @@ def _get_value(self, label, takeable: bool = False):
10651065
return self.iloc[loc]
10661066

10671067
def _setitem(self, key, value) -> None:
1068-
# if not PYPY:
1069-
# if sys.getrefcount(self) <= 3:
1070-
# warnings.warn(
1071-
# _chained_assignment_msg, ChainedAssignmentError, stacklevel=2
1072-
# )
1073-
10741068
check_dict_or_set_indexers(key)
10751069
key = com.apply_if_callable(key, self)
10761070

0 commit comments

Comments
 (0)