From 6d714d6d3996d1773af4e0c186a470f00c0f5cf9 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 26 Mar 2024 20:10:28 -0700 Subject: [PATCH] CLN: remove no-longer-needed warning filters --- pandas/core/generic.py | 8 +------- pandas/io/formats/xml.py | 9 +-------- pandas/io/json/_json.py | 9 +-------- pandas/io/stata.py | 8 +------- pandas/plotting/_matplotlib/core.py | 8 +------- pandas/tests/extension/test_masked.py | 10 +--------- pandas/tests/frame/indexing/test_where.py | 2 -- pandas/tests/frame/test_reductions.py | 1 - pandas/tests/frame/test_stack_unstack.py | 1 - pandas/tests/groupby/test_numeric_only.py | 1 - pandas/tests/series/test_api.py | 1 - pandas/tests/series/test_logical_ops.py | 1 - 12 files changed, 6 insertions(+), 53 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ebcb700e656f6..a7545fb8d98de 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9660,13 +9660,7 @@ def _where( # make sure we are boolean fill_value = bool(inplace) - with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", - "Downcasting object dtype arrays", - category=FutureWarning, - ) - cond = cond.fillna(fill_value) + cond = cond.fillna(fill_value) cond = cond.infer_objects() msg = "Boolean array expected for the condition, not {dtype}" diff --git a/pandas/io/formats/xml.py b/pandas/io/formats/xml.py index 702430642a597..47f162e93216d 100644 --- a/pandas/io/formats/xml.py +++ b/pandas/io/formats/xml.py @@ -11,7 +11,6 @@ Any, final, ) -import warnings from pandas.errors import AbstractMethodError from pandas.util._decorators import ( @@ -208,13 +207,7 @@ def _process_dataframe(self) -> dict[int | str, dict[str, Any]]: df = df.reset_index() if self.na_rep is not None: - with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", - "Downcasting object dtype arrays", - category=FutureWarning, - ) - df = df.fillna(self.na_rep) + df = df.fillna(self.na_rep) return df.to_dict(orient="index") diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index 8f4028c1ead3a..13d74e935f786 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -16,7 +16,6 @@ final, overload, ) -import warnings import numpy as np @@ -1173,13 +1172,7 @@ def _try_convert_data( if all(notna(data)): return data, False - with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", - "Downcasting object dtype arrays", - category=FutureWarning, - ) - filled = data.fillna(np.nan) + filled = data.fillna(np.nan) return filled, True diff --git a/pandas/io/stata.py b/pandas/io/stata.py index fe8b4896d097e..3ec077806d6c4 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -2887,13 +2887,7 @@ def _prepare_data(self) -> np.rec.recarray: for i, col in enumerate(data): typ = typlist[i] if typ <= self._max_string_length: - with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", - "Downcasting object dtype arrays", - category=FutureWarning, - ) - dc = data[col].fillna("") + dc = data[col].fillna("") data[col] = dc.apply(_pad_bytes, args=(typ,)) stype = f"S{typ}" dtypes[col] = stype diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index dbd2743345a38..700136bca8da7 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1725,13 +1725,7 @@ def _kind(self) -> Literal["area"]: def __init__(self, data, **kwargs) -> None: kwargs.setdefault("stacked", True) - with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", - "Downcasting object dtype arrays", - category=FutureWarning, - ) - data = data.fillna(value=0) + data = data.fillna(value=0) LinePlot.__init__(self, data, **kwargs) if not self.stacked: diff --git a/pandas/tests/extension/test_masked.py b/pandas/tests/extension/test_masked.py index 5481e50de10bb..69ce42203d510 100644 --- a/pandas/tests/extension/test_masked.py +++ b/pandas/tests/extension/test_masked.py @@ -14,8 +14,6 @@ """ -import warnings - import numpy as np import pytest @@ -215,13 +213,7 @@ def _cast_pointwise_result(self, op_name: str, obj, other, pointwise_result): if sdtype.kind in "iu": if op_name in ("__rtruediv__", "__truediv__", "__div__"): - with warnings.catch_warnings(): - warnings.filterwarnings( - "ignore", - "Downcasting object dtype arrays", - category=FutureWarning, - ) - filled = expected.fillna(np.nan) + filled = expected.fillna(np.nan) expected = filled.astype("Float64") else: # combine method result in 'biggest' (int64) dtype diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 8b3596debc0b8..aeffc4835a347 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -96,7 +96,6 @@ def test_where_upcasting(self): tm.assert_series_equal(result, expected) - @pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") def test_where_alignment(self, where_frame, float_string_frame): # aligning def _check_align(df, cond, other, check_dtypes=True): @@ -171,7 +170,6 @@ def test_where_invalid(self): with pytest.raises(ValueError, match=msg): df.mask(0) - @pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") def test_where_set(self, where_frame, float_string_frame, mixed_int_frame): # where inplace diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 408cb0ab6fc5c..5b9dd9e5b8aa6 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1272,7 +1272,6 @@ def test_any_all_bool_with_na( ): getattr(bool_frame_with_na, all_boolean_reductions)(axis=axis, bool_only=False) - @pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") def test_any_all_bool_frame(self, all_boolean_reductions, bool_frame_with_na): # GH#12863: numpy gives back non-boolean data for object type # so fill NaNs to compare with pandas behavior diff --git a/pandas/tests/frame/test_stack_unstack.py b/pandas/tests/frame/test_stack_unstack.py index 0b6b38340de9e..09235f154b188 100644 --- a/pandas/tests/frame/test_stack_unstack.py +++ b/pandas/tests/frame/test_stack_unstack.py @@ -1223,7 +1223,6 @@ def test_stack_preserve_categorical_dtype_values(self, future_stack): @pytest.mark.filterwarnings( "ignore:The previous implementation of stack is deprecated" ) - @pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") @pytest.mark.parametrize( "index", [ diff --git a/pandas/tests/groupby/test_numeric_only.py b/pandas/tests/groupby/test_numeric_only.py index 55a79863f206b..33cdd1883e1b9 100644 --- a/pandas/tests/groupby/test_numeric_only.py +++ b/pandas/tests/groupby/test_numeric_only.py @@ -310,7 +310,6 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys): method(*args, **kwargs) -@pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") @pytest.mark.parametrize("dtype", [bool, int, float, object]) def test_deprecate_numeric_only_series(dtype, groupby_func, request): # GH#46560 diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 0ace43f608b5a..7b45a267a4572 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -195,7 +195,6 @@ def test_series_datetimelike_attribute_access_invalid(self): with pytest.raises(AttributeError, match=msg): ser.weekday - @pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") @pytest.mark.parametrize( "kernel, has_numeric_only", [ diff --git a/pandas/tests/series/test_logical_ops.py b/pandas/tests/series/test_logical_ops.py index 757f63dd86904..b76b69289b72f 100644 --- a/pandas/tests/series/test_logical_ops.py +++ b/pandas/tests/series/test_logical_ops.py @@ -15,7 +15,6 @@ class TestSeriesLogicalOps: - @pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") @pytest.mark.parametrize("bool_op", [operator.and_, operator.or_, operator.xor]) def test_bool_operators_with_nas(self, bool_op): # boolean &, |, ^ should work with object arrays and propagate NAs