Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e209a35

Browse files
jorisvandenbosschengoldbaum
andauthored
CoW: disable chained assignment detection for Python 3.14 (#62324)
Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
1 parent 6ad23cf commit e209a35

File tree

9 files changed

+48
-27
lines changed

9 files changed

+48
-27
lines changed

‎.github/workflows/unit-tests.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ jobs:
358358
359359
- name: Run Tests
360360
uses: ./.github/actions/run-tests
361-
# TEMP allow this to fail until we fixed all test failures (related to chained assignment warnings)
362-
continue-on-error: true
363361

364362
# NOTE: this job must be kept in sync with the Pyodide build job in wheels.yml
365363
emscripten:

‎pandas/_testing/contexts.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
)
1313
import uuid
1414

15-
from pandas.compat import PYPY
15+
from pandas.compat import (
16+
PYPY,
17+
WARNING_CHECK_DISABLED,
18+
)
1619
from pandas.errors import ChainedAssignmentError
1720

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

166-
if PYPY:
169+
if PYPYorWARNING_CHECK_DISABLED:
167170
if not extra_warnings:
168171
from contextlib import nullcontext
169172

‎pandas/compat/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
PY312,
2222
PY314,
2323
PYPY,
24+
WARNING_CHECK_DISABLED,
2425
WASM,
2526
)
2627
from pandas.compat.numpy import is_numpy_dev
@@ -158,6 +159,7 @@ def is_ci_environment() -> bool:
158159
"PY314",
159160
"PYARROW_MIN_VERSION",
160161
"PYPY",
162+
"WARNING_CHECK_DISABLED",
161163
"WASM",
162164
"is_numpy_dev",
163165
"pa_version_under14p0",

‎pandas/compat/_constants.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
WASM = (sys.platform == "emscripten") or (platform.machine() in ["wasm32", "wasm64"])
2020
ISMUSL = "musl" in (sysconfig.get_config_var("HOST_GNU_TYPE") or "")
2121
REF_COUNT = 2
22+
WARNING_CHECK_DISABLED = PY314
23+
2224

2325
__all__ = [
2426
"IS64",

‎pandas/core/frame.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
from pandas._libs.hashtable import duplicated
5151
from pandas._libs.lib import is_range_indexer
5252
from pandas.compat import PYPY
53-
from pandas.compat._constants import REF_COUNT
53+
from pandas.compat._constants import (
54+
REF_COUNT,
55+
WARNING_CHECK_DISABLED,
56+
)
5457
from pandas.compat._optional import import_optional_dependency
5558
from pandas.compat.numpy import function as nv
5659
from pandas.errors import (
@@ -4296,8 +4299,8 @@ def __setitem__(self, key, value) -> None:
42964299
z 3 50
42974300
# Values for 'a' and 'b' are completely ignored!
42984301
"""
4299-
if not PYPY:
4300-
if sys.getrefcount(self) <= 3:
4302+
if not PYPYandnotWARNING_CHECK_DISABLED:
4303+
if sys.getrefcount(self) <= REF_COUNT+1:
43014304
warnings.warn(
43024305
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
43034306
)
@@ -9211,7 +9214,7 @@ def update(
92119214
1 2 500.0
92129215
2 3 6.0
92139216
"""
9214-
if not PYPY:
9217+
if not PYPYandnotWARNING_CHECK_DISABLED:
92159218
if sys.getrefcount(self) <= REF_COUNT:
92169219
warnings.warn(
92179220
_chained_assignment_method_msg,

‎pandas/core/generic.py‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@
8383
npt,
8484
)
8585
from pandas.compat import PYPY
86-
from pandas.compat._constants import REF_COUNT
86+
from pandas.compat._constants import (
87+
REF_COUNT,
88+
WARNING_CHECK_DISABLED,
89+
)
8790
from pandas.compat._optional import import_optional_dependency
8891
from pandas.compat.numpy import function as nv
8992
from pandas.errors import (
@@ -7070,7 +7073,7 @@ def fillna(
70707073
"""
70717074
inplace = validate_bool_kwarg(inplace, "inplace")
70727075
if inplace:
7073-
if not PYPY:
7076+
if not PYPYandnotWARNING_CHECK_DISABLED:
70747077
if sys.getrefcount(self) <= REF_COUNT:
70757078
warnings.warn(
70767079
_chained_assignment_method_msg,
@@ -7301,7 +7304,7 @@ def ffill(
73017304
"""
73027305
inplace = validate_bool_kwarg(inplace, "inplace")
73037306
if inplace:
7304-
if not PYPY:
7307+
if not PYPYandnotWARNING_CHECK_DISABLED:
73057308
if sys.getrefcount(self) <= REF_COUNT:
73067309
warnings.warn(
73077310
_chained_assignment_method_msg,
@@ -7441,7 +7444,7 @@ def bfill(
74417444
"""
74427445
inplace = validate_bool_kwarg(inplace, "inplace")
74437446
if inplace:
7444-
if not PYPY:
7447+
if not PYPYandnotWARNING_CHECK_DISABLED:
74457448
if sys.getrefcount(self) <= REF_COUNT:
74467449
warnings.warn(
74477450
_chained_assignment_method_msg,
@@ -7526,7 +7529,7 @@ def replace(
75267529

75277530
inplace = validate_bool_kwarg(inplace, "inplace")
75287531
if inplace:
7529-
if not PYPY:
7532+
if not PYPYandnotWARNING_CHECK_DISABLED:
75307533
if sys.getrefcount(self) <= REF_COUNT:
75317534
warnings.warn(
75327535
_chained_assignment_method_msg,
@@ -7889,7 +7892,7 @@ def interpolate(
78897892
inplace = validate_bool_kwarg(inplace, "inplace")
78907893

78917894
if inplace:
7892-
if not PYPY:
7895+
if not PYPYandnotWARNING_CHECK_DISABLED:
78937896
if sys.getrefcount(self) <= REF_COUNT:
78947897
warnings.warn(
78957898
_chained_assignment_method_msg,
@@ -8473,7 +8476,7 @@ def clip(
84738476
inplace = validate_bool_kwarg(inplace, "inplace")
84748477

84758478
if inplace:
8476-
if not PYPY:
8479+
if not PYPYandnotWARNING_CHECK_DISABLED:
84778480
if sys.getrefcount(self) <= REF_COUNT:
84788481
warnings.warn(
84798482
_chained_assignment_method_msg,
@@ -10083,7 +10086,7 @@ def where(
1008310086
"""
1008410087
inplace = validate_bool_kwarg(inplace, "inplace")
1008510088
if inplace:
10086-
if not PYPY:
10089+
if not PYPYandnotWARNING_CHECK_DISABLED:
1008710090
if sys.getrefcount(self) <= REF_COUNT:
1008810091
warnings.warn(
1008910092
_chained_assignment_method_msg,
@@ -10147,7 +10150,7 @@ def mask(
1014710150
) -> Self | None:
1014810151
inplace = validate_bool_kwarg(inplace, "inplace")
1014910152
if inplace:
10150-
if not PYPY:
10153+
if not PYPYandnotWARNING_CHECK_DISABLED:
1015110154
if sys.getrefcount(self) <= REF_COUNT:
1015210155
warnings.warn(
1015310156
_chained_assignment_method_msg,

‎pandas/core/indexing.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
from pandas._libs.indexing import NDFrameIndexerBase
1717
from pandas._libs.lib import item_from_zerodim
1818
from pandas.compat import PYPY
19+
from pandas.compat._constants import (
20+
REF_COUNT,
21+
WARNING_CHECK_DISABLED,
22+
)
1923
from pandas.errors import (
2024
AbstractMethodError,
2125
ChainedAssignmentError,
@@ -913,8 +917,8 @@ def _ensure_listlike_indexer(self, key, axis=None, value=None) -> None:
913917

914918
@final
915919
def __setitem__(self, key, value) -> None:
916-
if not PYPY:
917-
if sys.getrefcount(self.obj) <= 2:
920+
if not PYPYandnotWARNING_CHECK_DISABLED:
921+
if sys.getrefcount(self.obj) <= REF_COUNT:
918922
warnings.warn(
919923
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
920924
)
@@ -2581,8 +2585,8 @@ def __getitem__(self, key):
25812585
return super().__getitem__(key)
25822586

25832587
def __setitem__(self, key, value) -> None:
2584-
if not PYPY:
2585-
if sys.getrefcount(self.obj) <= 2:
2588+
if not PYPYandnotWARNING_CHECK_DISABLED:
2589+
if sys.getrefcount(self.obj) <= REF_COUNT:
25862590
warnings.warn(
25872591
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
25882592
)
@@ -2612,8 +2616,8 @@ def _convert_key(self, key):
26122616
return key
26132617

26142618
def __setitem__(self, key, value) -> None:
2615-
if not PYPY:
2616-
if sys.getrefcount(self.obj) <= 2:
2619+
if not PYPYandnotWARNING_CHECK_DISABLED:
2620+
if sys.getrefcount(self.obj) <= REF_COUNT:
26172621
warnings.warn(
26182622
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
26192623
)

‎pandas/core/series.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
)
3636
from pandas._libs.lib import is_range_indexer
3737
from pandas.compat import PYPY
38-
from pandas.compat._constants import REF_COUNT
38+
from pandas.compat._constants import (
39+
REF_COUNT,
40+
WARNING_CHECK_DISABLED,
41+
)
3942
from pandas.compat._optional import import_optional_dependency
4043
from pandas.compat.numpy import function as nv
4144
from pandas.errors import (
@@ -1055,8 +1058,8 @@ def _get_value(self, label, takeable: bool = False):
10551058
return self.iloc[loc]
10561059

10571060
def __setitem__(self, key, value) -> None:
1058-
if not PYPY:
1059-
if sys.getrefcount(self) <= 3:
1061+
if not PYPYandnotWARNING_CHECK_DISABLED:
1062+
if sys.getrefcount(self) <= REF_COUNT+1:
10601063
warnings.warn(
10611064
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
10621065
)
@@ -3324,7 +3327,7 @@ def update(self, other: Series | Sequence | Mapping) -> None:
33243327
2 3
33253328
dtype: int64
33263329
"""
3327-
if not PYPY:
3330+
if not PYPYandnotWARNING_CHECK_DISABLED:
33283331
if sys.getrefcount(self) <= REF_COUNT:
33293332
warnings.warn(
33303333
_chained_assignment_method_msg,

‎pandas/tests/copy_view/test_chained_assignment_deprecation.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import pytest
33

4+
from pandas.compat import WARNING_CHECK_DISABLED
45
from pandas.errors import ChainedAssignmentError
56

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

1819
# using custom check instead of tm.assert_produces_warning because that doesn't
1920
# fail if multiple warnings are raised
21+
if WARNING_CHECK_DISABLED:
22+
return
2023
with pytest.warns() as record: # noqa: TID251
2124
df["a"][indexer] = 0
2225
assert len(record) == 1

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /