Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,6 @@ jobs:
- name: Run Tests
uses: ./.github/actions/run-tests
# TEMP allow this to fail until we fixed all test failures (related to chained assignment warnings)
continue-on-error: true

# NOTE: this job must be kept in sync with the Pyodide build job in wheels.yml
emscripten:
Expand Down
7 changes: 5 additions & 2 deletions pandas/_testing/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
)
import uuid

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

from pandas.io.common import get_handle
Expand Down Expand Up @@ -163,7 +166,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:
if PYPY or WARNING_CHECK_DISABLED:
if not extra_warnings:
from contextlib import nullcontext

Expand Down
2 changes: 2 additions & 0 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
PY312,
PY314,
PYPY,
WARNING_CHECK_DISABLED,
WASM,
)
from pandas.compat.numpy import is_numpy_dev
Expand Down Expand Up @@ -158,6 +159,7 @@ def is_ci_environment() -> bool:
"PY314",
"PYARROW_MIN_VERSION",
"PYPY",
"WARNING_CHECK_DISABLED",
"WASM",
"is_numpy_dev",
"pa_version_under14p0",
Expand Down
2 changes: 2 additions & 0 deletions pandas/compat/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
WASM = (sys.platform == "emscripten") or (platform.machine() in ["wasm32", "wasm64"])
ISMUSL = "musl" in (sysconfig.get_config_var("HOST_GNU_TYPE") or "")
REF_COUNT = 2
WARNING_CHECK_DISABLED = PY314


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

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

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

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

@final
def __setitem__(self, key, value) -> None:
if not PYPY:
if sys.getrefcount(self.obj) <= 2:
if not PYPY and not WARNING_CHECK_DISABLED:
if sys.getrefcount(self.obj) <= REF_COUNT:
warnings.warn(
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
)
Expand Down Expand Up @@ -2581,8 +2585,8 @@ def __getitem__(self, key):
return super().__getitem__(key)

def __setitem__(self, key, value) -> None:
if not PYPY:
if sys.getrefcount(self.obj) <= 2:
if not PYPY and not WARNING_CHECK_DISABLED:
if sys.getrefcount(self.obj) <= REF_COUNT:
warnings.warn(
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
)
Expand Down Expand Up @@ -2612,8 +2616,8 @@ def _convert_key(self, key):
return key

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

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

from pandas.compat import WARNING_CHECK_DISABLED
from pandas.errors import ChainedAssignmentError

from pandas import DataFrame
Expand All @@ -17,6 +18,8 @@ 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_DISABLED:
return
with pytest.warns() as record: # noqa: TID251
df["a"][indexer] = 0
assert len(record) == 1
Expand Down
Loading