From bc7912cdc015a0d4396dca2638370b77ffec9849 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 25 Jul 2023 18:08:16 -0700 Subject: [PATCH 1/5] DEPR: fillna downcasting from object dtype --- doc/source/whatsnew/v2.1.0.rst | 1 + pandas/core/generic.py | 9 +++++- pandas/core/internals/blocks.py | 36 +++++++++++++++++---- pandas/io/formats/xml.py | 9 +++++- pandas/io/json/_json.py | 11 ++++++- pandas/io/stata.py | 9 +++++- pandas/plotting/_matplotlib/core.py | 8 ++++- pandas/tests/extension/test_integer.py | 11 ++++++- pandas/tests/frame/indexing/test_where.py | 2 ++ pandas/tests/frame/methods/test_fillna.py | 7 ++-- pandas/tests/frame/test_arithmetic.py | 12 +++++-- pandas/tests/frame/test_logical_ops.py | 1 + pandas/tests/frame/test_reductions.py | 1 + pandas/tests/frame/test_stack_unstack.py | 2 ++ pandas/tests/groupby/test_function.py | 1 + pandas/tests/series/methods/test_reindex.py | 8 +++-- pandas/tests/series/test_api.py | 1 + pandas/tests/series/test_arithmetic.py | 10 +++--- pandas/tests/series/test_logical_ops.py | 1 + 19 files changed, 117 insertions(+), 23 deletions(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 8cf7543ae075b..45770bad097bf 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -375,6 +375,7 @@ Deprecations - Deprecated the use of non-supported datetime64 and timedelta64 resolutions with :func:`pandas.array`. Supported resolutions are: "s", "ms", "us", "ns" resolutions (:issue:`53058`) - Deprecated values "pad", "ffill", "bfill", "backfill" for :meth:`Series.interpolate` and :meth:`DataFrame.interpolate`, use ``obj.ffill()`` or ``obj.bfill()`` instead (:issue:`53581`) - Deprecated the behavior of :meth:`Index.argmax`, :meth:`Index.argmin`, :meth:`Series.argmax`, :meth:`Series.argmin` with either all-NAs and skipna=True or any-NAs and skipna=False returning -1; in a future version this will raise ``ValueError`` (:issue:`33941`, :issue:`33942`) +- Deprecating downcasting the results of :meth:`DataFrame.fillna`, :meth:`Series.fillna`, :meth:`DataFrame.ffill`, :meth:`Series.ffill`, :meth:`DataFrame.bfill`, :meth:`Series.bfill` in object-dtype cases (:issue:`??`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 9d09665b15be9..44947225139d3 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10174,7 +10174,14 @@ def _where( # make sure we are boolean fill_value = bool(inplace) - cond = cond.fillna(fill_value) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + "Downcasting object dtype arrays", + category=FutureWarning, + ) + cond = cond.fillna(fill_value) + cond = cond.infer_objects(copy=False) msg = "Boolean array expected for the condition, not {dtype}" diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 64906d8792a8a..bac65648facd7 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -10,6 +10,7 @@ cast, final, ) +import warnings import numpy as np @@ -41,6 +42,7 @@ ) from pandas.errors import AbstractMethodError from pandas.util._decorators import cache_readonly +from pandas.util._exceptions import find_stack_level from pandas.util._validators import validate_bool_kwarg from pandas.core.dtypes.astype import ( @@ -455,7 +457,11 @@ def coerce_to_target_dtype(self, other) -> Block: @final def _maybe_downcast( - self, blocks: list[Block], downcast=None, using_cow: bool = False + self, + blocks: list[Block], + downcast=None, + using_cow: bool = False, + caller: str | None = None, ) -> list[Block]: if downcast is False: return blocks @@ -467,9 +473,23 @@ def _maybe_downcast( # but ATM it breaks too much existing code. # split and convert the blocks - return extend_blocks( + casted = extend_blocks( [blk.convert(using_cow=using_cow, copy=not using_cow) for blk in blocks] ) + if caller == "fillna": + if len(casted) != len(blocks) or not all( + x.dtype == y.dtype for x, y in zip(casted, blocks) + ): + # GH#11537 + warnings.warn( + "Downcasting object dtype arrays on .fillna, .ffill, .bfill " + "is deprecated and will change in a future version. " + "Call result.infer_objects(copy=False) instead.", + FutureWarning, + stacklevel=find_stack_level(), + ) + + return casted if downcast is None: return blocks @@ -1349,7 +1369,9 @@ def fillna( else: # GH#45423 consistent downcasting on no-ops. nb = self.copy(deep=not using_cow) - nbs = nb._maybe_downcast([nb], downcast=downcast, using_cow=using_cow) + nbs = nb._maybe_downcast( + [nb], downcast=downcast, using_cow=using_cow, caller="fillna" + ) return nbs if limit is not None: @@ -1367,7 +1389,9 @@ def fillna( # different behavior in _maybe_downcast. return extend_blocks( [ - blk._maybe_downcast([blk], downcast=downcast, using_cow=using_cow) + blk._maybe_downcast( + [blk], downcast=downcast, using_cow=using_cow, caller="fillna" + ) for blk in nbs ] ) @@ -1408,7 +1432,7 @@ def pad_or_backfill( data = extract_array(new_values, extract_numpy=True) nb = self.make_block_same_class(data, refs=refs) - return nb._maybe_downcast([nb], downcast, using_cow) + return nb._maybe_downcast([nb], downcast, using_cow, caller="fillna") @final def interpolate( @@ -1941,7 +1965,7 @@ def fillna( refs = None new_values = self.values.fillna(value=value, method=None, limit=limit) nb = self.make_block_same_class(new_values, refs=refs) - return nb._maybe_downcast([nb], downcast, using_cow=using_cow) + return nb._maybe_downcast([nb], downcast, using_cow=using_cow, caller="fillna") @cache_readonly def shape(self) -> Shape: diff --git a/pandas/io/formats/xml.py b/pandas/io/formats/xml.py index ee19f27fe8df6..6aa99944d705b 100644 --- a/pandas/io/formats/xml.py +++ b/pandas/io/formats/xml.py @@ -9,6 +9,7 @@ TYPE_CHECKING, Any, ) +import warnings from pandas.errors import AbstractMethodError from pandas.util._decorators import doc @@ -202,7 +203,13 @@ def process_dataframe(self) -> dict[int | str, dict[str, Any]]: df = df.reset_index() if self.na_rep is not None: - df = df.fillna(self.na_rep) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + "Downcasting object dtype arrays", + category=FutureWarning, + ) + 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 fb45622dac3af..a05fe9075a897 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -1216,7 +1216,16 @@ def _try_convert_data( if not self.dtype: if all(notna(data)): return data, False - return data.fillna(np.nan), True + + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + "Downcasting object dtype arrays", + category=FutureWarning, + ) + filled = data.fillna(np.nan) + + return filled, True elif self.dtype is True: pass diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 633f67cac4643..23663e65d60e6 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -2912,7 +2912,14 @@ def _prepare_data(self) -> np.recarray: for i, col in enumerate(data): typ = typlist[i] if typ <= self._max_string_length: - data[col] = data[col].fillna("").apply(_pad_bytes, args=(typ,)) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + "Downcasting object dtype arrays", + category=FutureWarning, + ) + dc = data[col].fillna("") + data[col] = dc.apply(_pad_bytes, args=(typ,)) stype = f"S{typ}" dtypes[col] = stype data[col] = data[col].astype(stype) diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index c62f73271577d..d88605db60720 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -1538,7 +1538,13 @@ def _kind(self) -> Literal["area"]: def __init__(self, data, **kwargs) -> None: kwargs.setdefault("stacked", True) - data = data.fillna(value=0) + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + "Downcasting object dtype arrays", + category=FutureWarning, + ) + data = data.fillna(value=0) LinePlot.__init__(self, data, **kwargs) if not self.stacked: diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index 448f70d54e61e..b09f05a18ba92 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -13,6 +13,8 @@ be added to the array-specific tests in `pandas/tests/arrays/`. """ +import warnings + import numpy as np import pytest @@ -136,7 +138,14 @@ def _check_op(self, s, op, other, op_name, exc=NotImplementedError): expected = self._combine(s, other, op) if op_name in ("__rtruediv__", "__truediv__", "__div__"): - expected = expected.fillna(np.nan).astype("Float64") + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + "Downcasting object dtype arrays", + category=FutureWarning, + ) + filled = expected.fillna(np.nan) + expected = filled.astype("Float64") else: # combine method result in 'biggest' (int64) dtype expected = expected.astype(sdtype) diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 562f2fbe55c25..cece1473c0f04 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -94,6 +94,7 @@ 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): @@ -164,6 +165,7 @@ 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): # where inplace diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index a5f6f58e66392..0409a60588f32 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -360,7 +360,9 @@ def test_fillna_dtype_conversion(self): expected = Series([np.dtype("object")] * 5, index=[1, 2, 3, 4, 5]) tm.assert_series_equal(result, expected) - result = df.fillna(1) + msg = "Downcasting object dtype arrays" + with tm.assert_produces_warning(FutureWarning, match=msg): + result = df.fillna(1) expected = DataFrame(1, index=["A", "B", "C"], columns=[1, 2, 3, 4, 5]) tm.assert_frame_equal(result, expected) @@ -817,7 +819,8 @@ def test_fillna_nones_inplace(): [[None, None], [None, None]], columns=["A", "B"], ) - with tm.assert_produces_warning(False): + msg = "Downcasting object dtype arrays" + with tm.assert_produces_warning(FutureWarning, match=msg): df.fillna(value={"A": 1, "B": 2}, inplace=True) expected = DataFrame([[1, 2], [1, 2]], columns=["A", "B"]) diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 52b60a0b83025..abf87e579cb8d 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -1242,7 +1242,9 @@ def test_operators_none_as_na(self, op): # since filling converts dtypes from object, changed expected to be # object - filled = df.fillna(np.nan) + msg = "Downcasting object dtype arrays" + with tm.assert_produces_warning(FutureWarning, match=msg): + filled = df.fillna(np.nan) result = op(df, 3) expected = op(filled, 3).astype(object) expected[pd.isna(expected)] = np.nan @@ -1253,10 +1255,14 @@ def test_operators_none_as_na(self, op): expected[pd.isna(expected)] = np.nan tm.assert_frame_equal(result, expected) - result = op(df, df.fillna(7)) + msg = "Downcasting object dtype arrays" + with tm.assert_produces_warning(FutureWarning, match=msg): + result = op(df, df.fillna(7)) tm.assert_frame_equal(result, expected) - result = op(df.fillna(7), df) + msg = "Downcasting object dtype arrays" + with tm.assert_produces_warning(FutureWarning, match=msg): + result = op(df.fillna(7), df) tm.assert_frame_equal(result, expected) @pytest.mark.parametrize("op,res", [("__eq__", False), ("__ne__", True)]) diff --git a/pandas/tests/frame/test_logical_ops.py b/pandas/tests/frame/test_logical_ops.py index 2cc3b67e7ac02..a15d7d7f93f01 100644 --- a/pandas/tests/frame/test_logical_ops.py +++ b/pandas/tests/frame/test_logical_ops.py @@ -151,6 +151,7 @@ def _check_unary_op(op): _check_unary_op(operator.inv) # TODO: belongs elsewhere + @pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") def test_logical_with_nas(self): d = DataFrame({"a": [np.nan, False], "b": [True, True]}) diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 25ddb1397e749..12d32f9a8569e 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1152,6 +1152,7 @@ def test_any_all_mixed_float(self, opname, axis, bool_only, float_string_frame): def test_any_all_bool_with_na(self, opname, axis, bool_frame_with_na): getattr(bool_frame_with_na, opname)(axis=axis, bool_only=False) + @pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") @pytest.mark.parametrize("opname", ["any", "all"]) def test_any_all_bool_frame(self, opname, bool_frame_with_na): # GH#12863: numpy gives back non-boolean data for object type diff --git a/pandas/tests/frame/test_stack_unstack.py b/pandas/tests/frame/test_stack_unstack.py index a48728a778877..0d3bb2e86d92e 100644 --- a/pandas/tests/frame/test_stack_unstack.py +++ b/pandas/tests/frame/test_stack_unstack.py @@ -1126,6 +1126,7 @@ def test_stack_preserve_categorical_dtype_values(self): ) tm.assert_series_equal(result, expected) + @pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning") @pytest.mark.parametrize( "index, columns", [ @@ -1136,6 +1137,7 @@ def test_stack_preserve_categorical_dtype_values(self): ) def test_stack_multi_columns_non_unique_index(self, index, columns): # GH-28301 + df = DataFrame(index=index, columns=columns).fillna(1) stacked = df.stack() new_index = MultiIndex.from_tuples(stacked.index.to_numpy()) diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index 04a699cfede56..2217149959f7a 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -1505,6 +1505,7 @@ 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/methods/test_reindex.py b/pandas/tests/series/methods/test_reindex.py index cf042b310ff63..2c4367e89d611 100644 --- a/pandas/tests/series/methods/test_reindex.py +++ b/pandas/tests/series/methods/test_reindex.py @@ -157,7 +157,9 @@ def test_reindex_inference(): # inference of new dtype s = Series([True, False, False, True], index=list("abcd")) new_index = "agc" - result = s.reindex(list(new_index)).ffill() + msg = "Downcasting object dtype arrays on" + with tm.assert_produces_warning(FutureWarning, match=msg): + result = s.reindex(list(new_index)).ffill() expected = Series([True, True, False], index=list(new_index)) tm.assert_series_equal(result, expected) @@ -165,7 +167,9 @@ def test_reindex_inference(): def test_reindex_downcasting(): # GH4618 shifted series downcasting s = Series(False, index=range(0, 5)) - result = s.shift(1).bfill() + msg = "Downcasting object dtype arrays on" + with tm.assert_produces_warning(FutureWarning, match=msg): + result = s.shift(1).bfill() expected = Series(False, index=range(0, 5)) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 7d70206585be4..0d242a3427ccf 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -205,6 +205,7 @@ 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_arithmetic.py b/pandas/tests/series/test_arithmetic.py index a0edfae606e3f..e4b7e6fcc98b7 100644 --- a/pandas/tests/series/test_arithmetic.py +++ b/pandas/tests/series/test_arithmetic.py @@ -639,10 +639,12 @@ def test_comparison_operators_with_nas(self, comparison_op): result = comparison_op(ser, val) expected = comparison_op(ser.dropna(), val).reindex(ser.index) - if comparison_op is operator.ne: - expected = expected.fillna(True).astype(bool) - else: - expected = expected.fillna(False).astype(bool) + msg = "Downcasting object dtype arrays" + with tm.assert_produces_warning(FutureWarning, match=msg): + if comparison_op is operator.ne: + expected = expected.fillna(True).astype(bool) + else: + expected = expected.fillna(False).astype(bool) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/test_logical_ops.py b/pandas/tests/series/test_logical_ops.py index 19412db91b487..a6723811b2541 100644 --- a/pandas/tests/series/test_logical_ops.py +++ b/pandas/tests/series/test_logical_ops.py @@ -15,6 +15,7 @@ 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 From 17783d916b97f85e23e8fecca8c28ebea6047fbb Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 25 Jul 2023 18:09:21 -0700 Subject: [PATCH 2/5] GH ref --- doc/source/whatsnew/v2.1.0.rst | 2 +- pandas/core/internals/blocks.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 45770bad097bf..7d27c93ac2c39 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -375,7 +375,7 @@ Deprecations - Deprecated the use of non-supported datetime64 and timedelta64 resolutions with :func:`pandas.array`. Supported resolutions are: "s", "ms", "us", "ns" resolutions (:issue:`53058`) - Deprecated values "pad", "ffill", "bfill", "backfill" for :meth:`Series.interpolate` and :meth:`DataFrame.interpolate`, use ``obj.ffill()`` or ``obj.bfill()`` instead (:issue:`53581`) - Deprecated the behavior of :meth:`Index.argmax`, :meth:`Index.argmin`, :meth:`Series.argmax`, :meth:`Series.argmin` with either all-NAs and skipna=True or any-NAs and skipna=False returning -1; in a future version this will raise ``ValueError`` (:issue:`33941`, :issue:`33942`) -- Deprecating downcasting the results of :meth:`DataFrame.fillna`, :meth:`Series.fillna`, :meth:`DataFrame.ffill`, :meth:`Series.ffill`, :meth:`DataFrame.bfill`, :meth:`Series.bfill` in object-dtype cases (:issue:`??`) +- Deprecating downcasting the results of :meth:`DataFrame.fillna`, :meth:`Series.fillna`, :meth:`DataFrame.ffill`, :meth:`Series.ffill`, :meth:`DataFrame.bfill`, :meth:`Series.bfill` in object-dtype cases (:issue:`54261`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index bac65648facd7..08ee323b91450 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -480,7 +480,7 @@ def _maybe_downcast( if len(casted) != len(blocks) or not all( x.dtype == y.dtype for x, y in zip(casted, blocks) ): - # GH#11537 + # GH#54261 warnings.warn( "Downcasting object dtype arrays on .fillna, .ffill, .bfill " "is deprecated and will change in a future version. " From 15cd465b910c188e52b82cc6ea57f8c5b212994a Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 26 Jul 2023 10:59:08 -0700 Subject: [PATCH 3/5] suppress warning --- doc/source/user_guide/missing_data.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/user_guide/missing_data.rst b/doc/source/user_guide/missing_data.rst index ac7e383d6d7ff..ab346ff1e1e6a 100644 --- a/doc/source/user_guide/missing_data.rst +++ b/doc/source/user_guide/missing_data.rst @@ -689,6 +689,7 @@ contains NAs, an exception will be generated: However, these can be filled in using :meth:`~DataFrame.fillna` and it will work fine: .. ipython:: python + :okwarning: reindexed[crit.fillna(False)] reindexed[crit.fillna(True)] From fc9531ef4939e7bf99f4b3a925254d6a4513de70 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 22 Aug 2023 17:40:46 -0700 Subject: [PATCH 4/5] update test --- example | Bin 0 -> 7032 bytes pandas/tests/extension/test_masked.py | 11 ++++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 example diff --git a/example b/example new file mode 100644 index 0000000000000000000000000000000000000000..14533f15adaedee0eb7f33c0c578e8f113417050 GIT binary patch literal 7032 zcmeHL%}yIJ5cVegERYr`Mg6;Q%HJA&I4Yo+rWgXZL|QaO5rEnMgRSM*^JJt6ujfggq#63};_+9ycYcv({k2o3v_1=_%oijj`t(t53#bfjh29Ckd}nT&Khg=@}B>HPz*6Q36;@ z$%%n(IW0A_l$Z_inPRbMRVu_cC@IhLdAYO>3)K9klxvEOT)DDbT2*qvWtcyk&d3_@ z&ns$34+H+St*W(9%vEanQu&2dt@Ro|m(J3-NhLGtpE4Av@`Duq&OgN%^0OSQ#s4?O z0#W}&R0^?6ahvU6AGrY_7bqa`^?q}EFH<|T_Ya&v*WI?$fNBTtGf?SLDyyX>Lvj&Z zg>*$#*iUAuUWm-2i>Mpj#OLz-G@1co5tROka~SUoIU|U3E!(TxL9Kn#nz>l*zxSzV&MUF<@TD z?_nJ0`%PaW8Ti9`g0}B&x5Ih{)yllO+W;LC63~e0XHf0TkB>XOuG>nF@+;{^zU#E% z1O$D

e*mbFgpwQqDNaq6PE57w&=2q|7d96jC^d z5<9GjJG2U5{;=}BuI&ToX7BURDwnM-IY#pXcklCXF8xGlyewX6dIICefRv2oY=nEd zQ)yOJPRLKXa|t^2h4}cO7YDZUdHMO?#eDtVYb`AD6csLHg(*XpfzhiyB!Wf7G`2u& zf!G4E1!4=t7U*XS!21If!@%R64|}FMkHfq;U$iz#<@0&8chG1-{;JIN^TH&-H%%d%T42 zQLfi^b{zl8cq!0*VDlVaOoek#J%|M7_LcFc>8RTOw;jC9BJS{7hL4Z3h5b+C1{MD~ zeqIuO5Z^TYzP;aFH-7k?IQrhCXX literal 0 HcmV?d00001 diff --git a/pandas/tests/extension/test_masked.py b/pandas/tests/extension/test_masked.py index 7efb8fbad8cd1..3d78ab9342f58 100644 --- a/pandas/tests/extension/test_masked.py +++ b/pandas/tests/extension/test_masked.py @@ -13,6 +13,8 @@ be added to the array-specific tests in `pandas/tests/arrays/`. """ +import warnings + import numpy as np import pytest @@ -186,7 +188,14 @@ def _cast_pointwise_result(self, op_name: str, obj, other, pointwise_result): if sdtype.kind in "iu": if op_name in ("__rtruediv__", "__truediv__", "__div__"): - expected = expected.fillna(np.nan).astype("Float64") + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + "Downcasting object dtype arrays", + category=FutureWarning, + ) + filled = expected.fillna(np.nan) + expected = filled.astype("Float64") else: # combine method result in 'biggest' (int64) dtype expected = expected.astype(sdtype) From 991d95c2b4b1cf9d83a766ff2bac1c3f22f67e01 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Fri, 1 Sep 2023 10:24:23 -0700 Subject: [PATCH 5/5] Update doc/source/whatsnew/v2.1.0.rst Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- doc/source/whatsnew/v2.1.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 17a72cb437053..040ca048d1224 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -592,7 +592,6 @@ Other Deprecations - Deprecated the behavior of :meth:`Index.argmax`, :meth:`Index.argmin`, :meth:`Series.argmax`, :meth:`Series.argmin` with either all-NAs and ``skipna=True`` or any-NAs and ``skipna=False`` returning -1; in a future version this will raise ``ValueError`` (:issue:`33941`, :issue:`33942`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_sql` except ``name`` and ``con`` (:issue:`54229`) - Deprecated silently ignoring ``fill_value`` when passing both ``freq`` and ``fill_value`` to :meth:`DataFrame.shift`, :meth:`Series.shift` and :meth:`.DataFrameGroupBy.shift`; in a future version this will raise ``ValueError`` (:issue:`53832`) -- .. --------------------------------------------------------------------------- .. _whatsnew_210.performance: