Skip to content

Commit 3f708df

Browse files
committed
MNT: use a global constant for disabling the warning
1 parent e84db62 commit 3f708df

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

pandas/compat/_constants.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@
1919
PYPY = platform.python_implementation() == "PyPy"
2020
WASM = (sys.platform == "emscripten") or (platform.machine() in ["wasm32", "wasm64"])
2121
ISMUSL = "musl" in (sysconfig.get_config_var("HOST_GNU_TYPE") or "")
22-
if PY311:
23-
REF_COUNT = 2
24-
elif PY314:
25-
REF_COUNT = 1
26-
else:
27-
# Python 3.10 and older
28-
REF_COUNT = 3
22+
REF_COUNT = 2 if PY311 else 3
23+
# hopefully there is a workaround in Python 3.14.1
24+
WARNING_CHECK_BROKEN = PY314
2925

3026
__all__ = [
3127
"IS64",

pandas/core/frame.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from pandas._libs.hashtable import duplicated
5050
from pandas._libs.lib import is_range_indexer
5151
from pandas.compat import PYPY
52-
from pandas.compat._constants import REF_COUNT
52+
from pandas.compat._constants import REF_COUNT, WARNING_CHECK_BROKEN
5353
from pandas.compat._optional import import_optional_dependency
5454
from pandas.compat.numpy import function as nv
5555
from pandas.errors import (
@@ -4296,7 +4296,7 @@ def __setitem__(self, key, value) -> None:
42964296
z 3 50
42974297
# Values for 'a' and 'b' are completely ignored!
42984298
"""
4299-
if not PYPY and sys.version_info < (3, 14):
4299+
if not PYPY and not WARNING_CHECK_BROKEN:
43004300
if sys.getrefcount(self) <= REF_COUNT + 1:
43014301
warnings.warn(
43024302
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
@@ -9204,7 +9204,7 @@ def update(
92049204
1 2 500.0
92059205
2 3 6.0
92069206
"""
9207-
if not PYPY and sys.version_info < (3, 14):
9207+
if not PYPY and not WARNING_CHECK_BROKEN:
92089208
if sys.getrefcount(self) <= REF_COUNT:
92099209
warnings.warn(
92109210
_chained_assignment_method_msg,

pandas/core/generic.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
npt,
8484
)
8585
from pandas.compat import PYPY
86-
from pandas.compat._constants import REF_COUNT
86+
from pandas.compat._constants import REF_COUNT, WARNING_CHECK_BROKEN
8787
from pandas.compat._optional import import_optional_dependency
8888
from pandas.compat.numpy import function as nv
8989
from pandas.errors import (
@@ -7069,7 +7069,7 @@ def fillna(
70697069
"""
70707070
inplace = validate_bool_kwarg(inplace, "inplace")
70717071
if inplace:
7072-
if not PYPY and sys.version_info < (3, 14):
7072+
if not PYPY and WARNING_CHECK_BROKEN:
70737073
if sys.getrefcount(self) <= REF_COUNT:
70747074
warnings.warn(
70757075
_chained_assignment_method_msg,
@@ -7300,7 +7300,7 @@ def ffill(
73007300
"""
73017301
inplace = validate_bool_kwarg(inplace, "inplace")
73027302
if inplace:
7303-
if not PYPY and sys.version_info < (3, 14):
7303+
if not PYPY and WARNING_CHECK_BROKEN:
73047304
if sys.getrefcount(self) <= REF_COUNT:
73057305
warnings.warn(
73067306
_chained_assignment_method_msg,
@@ -7440,7 +7440,7 @@ def bfill(
74407440
"""
74417441
inplace = validate_bool_kwarg(inplace, "inplace")
74427442
if inplace:
7443-
if not PYPY and sys.version_info < (3, 14):
7443+
if not PYPY and WARNING_CHECK_BROKEN:
74447444
if sys.getrefcount(self) <= REF_COUNT:
74457445
warnings.warn(
74467446
_chained_assignment_method_msg,
@@ -7525,7 +7525,7 @@ def replace(
75257525

75267526
inplace = validate_bool_kwarg(inplace, "inplace")
75277527
if inplace:
7528-
if not PYPY and sys.version_info < (3, 14):
7528+
if not PYPY and WARNING_CHECK_BROKEN:
75297529
if sys.getrefcount(self) <= REF_COUNT:
75307530
warnings.warn(
75317531
_chained_assignment_method_msg,
@@ -7888,7 +7888,7 @@ def interpolate(
78887888
inplace = validate_bool_kwarg(inplace, "inplace")
78897889

78907890
if inplace:
7891-
if not PYPY and sys.version_info < (3, 14):
7891+
if not PYPY and WARNING_CHECK_BROKEN:
78927892
if sys.getrefcount(self) <= REF_COUNT:
78937893
warnings.warn(
78947894
_chained_assignment_method_msg,
@@ -8472,7 +8472,7 @@ def clip(
84728472
inplace = validate_bool_kwarg(inplace, "inplace")
84738473

84748474
if inplace:
8475-
if not PYPY and sys.version_info < (3, 14):
8475+
if not PYPY and WARNING_CHECK_BROKEN:
84768476
if sys.getrefcount(self) <= REF_COUNT:
84778477
warnings.warn(
84788478
_chained_assignment_method_msg,
@@ -10081,7 +10081,7 @@ def where(
1008110081
"""
1008210082
inplace = validate_bool_kwarg(inplace, "inplace")
1008310083
if inplace:
10084-
if not PYPY and sys.version_info < (3, 14):
10084+
if not PYPY and WARNING_CHECK_BROKEN:
1008510085
if sys.getrefcount(self) <= REF_COUNT:
1008610086
warnings.warn(
1008710087
_chained_assignment_method_msg,
@@ -10145,7 +10145,7 @@ def mask(
1014510145
) -> Self | None:
1014610146
inplace = validate_bool_kwarg(inplace, "inplace")
1014710147
if inplace:
10148-
if not PYPY and sys.version_info < (3, 14):
10148+
if not PYPY and WARNING_CHECK_BROKEN:
1014910149
if sys.getrefcount(self) <= REF_COUNT:
1015010150
warnings.warn(
1015110151
_chained_assignment_method_msg,

pandas/core/indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pandas._libs.indexing import NDFrameIndexerBase
1616
from pandas._libs.lib import item_from_zerodim
1717
from pandas.compat import PYPY
18-
from pandas.compat._constants import REF_COUNT
18+
from pandas.compat._constants import REF_COUNT, WARNING_CHECK_BROKEN
1919
from pandas.errors import (
2020
AbstractMethodError,
2121
ChainedAssignmentError,
@@ -914,7 +914,7 @@ def _ensure_listlike_indexer(self, key, axis=None, value=None) -> None:
914914

915915
@final
916916
def __setitem__(self, key, value) -> None:
917-
if not PYPY and sys.version_info < (3, 14):
917+
if not PYPY and not WARNING_CHECK_BROKEN:
918918
if sys.getrefcount(self.obj) <= REF_COUNT:
919919
warnings.warn(
920920
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2

pandas/core/series.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
)
3535
from pandas._libs.lib import is_range_indexer
3636
from pandas.compat import PYPY
37-
from pandas.compat._constants import REF_COUNT
37+
from pandas.compat._constants import REF_COUNT, WARNING_CHECK_BROKEN
3838
from pandas.compat._optional import import_optional_dependency
3939
from pandas.compat.numpy import function as nv
4040
from pandas.errors import (
@@ -1059,7 +1059,7 @@ def _get_value(self, label, takeable: bool = False):
10591059
return self.iloc[loc]
10601060

10611061
def __setitem__(self, key, value) -> None:
1062-
if not PYPY and sys.version_info < (3, 14):
1062+
if not PYPY and not WARNING_CHECK_BROKEN:
10631063
if sys.getrefcount(self) <= REF_COUNT + 1:
10641064
warnings.warn(
10651065
_chained_assignment_msg, ChainedAssignmentError, stacklevel=2
@@ -3338,7 +3338,7 @@ def update(self, other: Series | Sequence | Mapping) -> None:
33383338
2 3
33393339
dtype: int64
33403340
"""
3341-
if not PYPY and sys.version_info < (3, 14):
3341+
if not PYPY and not WARNING_CHECK_BROKEN:
33423342
if sys.getrefcount(self) <= REF_COUNT:
33433343
warnings.warn(
33443344
_chained_assignment_method_msg,

0 commit comments

Comments
 (0)