Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions pandas/_testing/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
)
import uuid

from pandas.compat import (
PYPY,
WARNING_CHECK_BROKEN,
)
from pandas.compat import PYPY
from pandas.errors import ChainedAssignmentError

from pandas.io.common import get_handle
Expand Down Expand Up @@ -166,7 +163,7 @@ def with_csv_dialect(name: str, **kwargs) -> Generator[None]:
def raises_chained_assignment_error(extra_warnings=(), extra_match=()):
from pandas._testing import assert_produces_warning

if PYPY or WARNING_CHECK_BROKEN:
if PYPY:
if not extra_warnings:
from contextlib import nullcontext

Expand Down
4 changes: 0 additions & 4 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
IS64,
ISMUSL,
PY312,
PY314,
PYPY,
WARNING_CHECK_BROKEN,
WASM,
)
from pandas.compat.numpy import is_numpy_dev
Expand Down Expand Up @@ -157,9 +155,7 @@ def is_ci_environment() -> bool:
"IS64",
"ISMUSL",
"PY312",
"PY314",
"PYPY",
"WARNING_CHECK_BROKEN",
"WASM",
"is_numpy_dev",
"pa_version_under12p1",
Expand Down
4 changes: 0 additions & 4 deletions pandas/compat/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
IS64 = sys.maxsize > 2**32

PY312 = sys.version_info >= (3, 12)
PY314 = sys.version_info >= (3, 14)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need this, I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, thanks, I had just reset all files in the actual package to its version on main, as all (except this) changes were related to the warning.
I was thinking to merge this without those changes, as then I would update my PR to actually fix those next (without needing to add and then remove it again)

PYPY = platform.python_implementation() == "PyPy"
WASM = (sys.platform == "emscripten") or (platform.machine() in ["wasm32", "wasm64"])
ISMUSL = "musl" in (sysconfig.get_config_var("HOST_GNU_TYPE") or "")
REF_COUNT = 2
# hopefully there is a workaround in Python 3.14.1
WARNING_CHECK_BROKEN = PY314


__all__ = [
"IS64",
Expand Down
11 changes: 4 additions & 7 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
from pandas._libs.hashtable import duplicated
from pandas._libs.lib import is_range_indexer
from pandas.compat import PYPY
from pandas.compat._constants import (
REF_COUNT,
WARNING_CHECK_BROKEN,
)
from pandas.compat._constants import REF_COUNT
from pandas.compat._optional import import_optional_dependency
from pandas.compat.numpy import function as nv
from pandas.errors import (
Expand Down Expand Up @@ -4299,8 +4296,8 @@ def __setitem__(self, key, value) -> None:
z 3 50
# Values for 'a' and 'b' are completely ignored!
"""
if not PYPY and not WARNING_CHECK_BROKEN:
if sys.getrefcount(self) <= REF_COUNT + 1:
if not PYPY:
if sys.getrefcount(self) <= 3:
warnings.warn(
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
)
Expand Down Expand Up @@ -9214,7 +9211,7 @@ def update(
1 2 500.0
2 3 6.0
"""
if not PYPY and not WARNING_CHECK_BROKEN:
if not PYPY:
if sys.getrefcount(self) <= REF_COUNT:
warnings.warn(
_chained_assignment_method_msg,
Expand Down
21 changes: 9 additions & 12 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@
npt,
)
from pandas.compat import PYPY
from pandas.compat._constants import (
REF_COUNT,
WARNING_CHECK_BROKEN,
)
from pandas.compat._constants import REF_COUNT
from pandas.compat._optional import import_optional_dependency
from pandas.compat.numpy import function as nv
from pandas.errors import (
Expand Down Expand Up @@ -7073,7 +7070,7 @@ def fillna(
"""
inplace = validate_bool_kwarg(inplace, "inplace")
if inplace:
if not PYPY and not WARNING_CHECK_BROKEN:
if not PYPY:
if sys.getrefcount(self) <= REF_COUNT:
warnings.warn(
_chained_assignment_method_msg,
Expand Down Expand Up @@ -7304,7 +7301,7 @@ def ffill(
"""
inplace = validate_bool_kwarg(inplace, "inplace")
if inplace:
if not PYPY and not WARNING_CHECK_BROKEN:
if not PYPY:
if sys.getrefcount(self) <= REF_COUNT:
warnings.warn(
_chained_assignment_method_msg,
Expand Down Expand Up @@ -7444,7 +7441,7 @@ def bfill(
"""
inplace = validate_bool_kwarg(inplace, "inplace")
if inplace:
if not PYPY and not WARNING_CHECK_BROKEN:
if not PYPY:
if sys.getrefcount(self) <= REF_COUNT:
warnings.warn(
_chained_assignment_method_msg,
Expand Down Expand Up @@ -7529,7 +7526,7 @@ def replace(

inplace = validate_bool_kwarg(inplace, "inplace")
if inplace:
if not PYPY and not WARNING_CHECK_BROKEN:
if not PYPY:
if sys.getrefcount(self) <= REF_COUNT:
warnings.warn(
_chained_assignment_method_msg,
Expand Down Expand Up @@ -7892,7 +7889,7 @@ def interpolate(
inplace = validate_bool_kwarg(inplace, "inplace")

if inplace:
if not PYPY and not WARNING_CHECK_BROKEN:
if not PYPY:
if sys.getrefcount(self) <= REF_COUNT:
warnings.warn(
_chained_assignment_method_msg,
Expand Down Expand Up @@ -8476,7 +8473,7 @@ def clip(
inplace = validate_bool_kwarg(inplace, "inplace")

if inplace:
if not PYPY and not WARNING_CHECK_BROKEN:
if not PYPY:
if sys.getrefcount(self) <= REF_COUNT:
warnings.warn(
_chained_assignment_method_msg,
Expand Down Expand Up @@ -10086,7 +10083,7 @@ def where(
"""
inplace = validate_bool_kwarg(inplace, "inplace")
if inplace:
if not PYPY and not WARNING_CHECK_BROKEN:
if not PYPY:
if sys.getrefcount(self) <= REF_COUNT:
warnings.warn(
_chained_assignment_method_msg,
Expand Down Expand Up @@ -10150,7 +10147,7 @@ def mask(
) -> Self | None:
inplace = validate_bool_kwarg(inplace, "inplace")
if inplace:
if not PYPY and not WARNING_CHECK_BROKEN:
if not PYPY:
if sys.getrefcount(self) <= REF_COUNT:
warnings.warn(
_chained_assignment_method_msg,
Expand Down
8 changes: 2 additions & 6 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
from pandas._libs.indexing import NDFrameIndexerBase
from pandas._libs.lib import item_from_zerodim
from pandas.compat import PYPY
from pandas.compat._constants import (
REF_COUNT,
WARNING_CHECK_BROKEN,
)
from pandas.errors import (
AbstractMethodError,
ChainedAssignmentError,
Expand Down Expand Up @@ -917,8 +913,8 @@ def _ensure_listlike_indexer(self, key, axis=None, value=None) -> None:

@final
def __setitem__(self, key, value) -> None:
if not PYPY and not WARNING_CHECK_BROKEN:
if sys.getrefcount(self.obj) <= REF_COUNT:
if not PYPY:
if sys.getrefcount(self.obj) <= 2:
warnings.warn(
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
)
Expand Down
11 changes: 4 additions & 7 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
)
from pandas._libs.lib import is_range_indexer
from pandas.compat import PYPY
from pandas.compat._constants import (
REF_COUNT,
WARNING_CHECK_BROKEN,
)
from pandas.compat._constants import REF_COUNT
from pandas.compat._optional import import_optional_dependency
from pandas.compat.numpy import function as nv
from pandas.errors import (
Expand Down Expand Up @@ -1058,8 +1055,8 @@ def _get_value(self, label, takeable: bool = False):
return self.iloc[loc]

def __setitem__(self, key, value) -> None:
if not PYPY and not WARNING_CHECK_BROKEN:
if sys.getrefcount(self) <= REF_COUNT + 1:
if not PYPY:
if sys.getrefcount(self) <= 3:
warnings.warn(
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
)
Expand Down Expand Up @@ -3336,7 +3333,7 @@ def update(self, other: Series | Sequence | Mapping) -> None:
2 3
dtype: int64
"""
if not PYPY and not WARNING_CHECK_BROKEN:
if not PYPY:
if sys.getrefcount(self) <= REF_COUNT:
warnings.warn(
_chained_assignment_method_msg,
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/copy_view/test_chained_assignment_deprecation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
import pytest

from pandas.compat import WARNING_CHECK_BROKEN
from pandas.errors import ChainedAssignmentError

from pandas import DataFrame
Expand All @@ -18,8 +17,6 @@ def test_series_setitem(indexer):

# using custom check instead of tm.assert_produces_warning because that doesn't
# fail if multiple warnings are raised
if WARNING_CHECK_BROKEN:
return
with pytest.warns() as record: # noqa: TID251
df["a"][indexer] = 0
assert len(record) == 1
Expand Down
Loading