diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index ae135fd41d977..18e970f9e89e2 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -139,6 +139,7 @@ Removal of prior version deprecations/changes - Removed ``year``, ``month``, ``quarter``, ``day``, ``hour``, ``minute``, and ``second`` keywords in the :class:`PeriodIndex` constructor, use :meth:`PeriodIndex.from_fields` instead (:issue:`55960`) - Removed deprecated argument ``obj`` in :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` (:issue:`53545`) - Removed deprecated behavior of :meth:`Series.agg` using :meth:`Series.apply` (:issue:`53325`) +- Removed option ``mode.use_inf_as_na``, convert inf entries to ``NaN`` before instead (:issue:`51684`) - Removed support for :class:`DataFrame` in :meth:`DataFrame.from_records`(:issue:`51697`) - Removed support for ``errors="ignore"`` in :func:`to_datetime`, :func:`to_timedelta` and :func:`to_numeric` (:issue:`55734`) - Removed support for ``slice`` in :meth:`DataFrame.take` (:issue:`51539`) diff --git a/pandas/_libs/missing.pxd b/pandas/_libs/missing.pxd index 5920649519442..899d729690451 100644 --- a/pandas/_libs/missing.pxd +++ b/pandas/_libs/missing.pxd @@ -7,8 +7,8 @@ from numpy cimport ( cpdef bint is_matching_na(object left, object right, bint nan_matches_none=*) cpdef bint check_na_tuples_nonequal(object left, object right) -cpdef bint checknull(object val, bint inf_as_na=*) -cpdef ndarray[uint8_t] isnaobj(ndarray arr, bint inf_as_na=*) +cpdef bint checknull(object val) +cpdef ndarray[uint8_t] isnaobj(ndarray arr) cdef bint is_null_datetime64(v) cdef bint is_null_timedelta64(v) diff --git a/pandas/_libs/missing.pyi b/pandas/_libs/missing.pyi index 282dcee3ed6cf..6bf30a03cef32 100644 --- a/pandas/_libs/missing.pyi +++ b/pandas/_libs/missing.pyi @@ -11,6 +11,6 @@ def is_matching_na( ) -> bool: ... def isposinf_scalar(val: object) -> bool: ... def isneginf_scalar(val: object) -> bool: ... -def checknull(val: object, inf_as_na: bool = ...) -> bool: ... -def isnaobj(arr: np.ndarray, inf_as_na: bool = ...) -> npt.NDArray[np.bool_]: ... +def checknull(val: object) -> bool: ... +def isnaobj(arr: np.ndarray) -> npt.NDArray[np.bool_]: ... def is_numeric_na(values: np.ndarray) -> npt.NDArray[np.bool_]: ... diff --git a/pandas/_libs/missing.pyx b/pandas/_libs/missing.pyx index 0fd1c2b21d5cd..2f44128cda822 100644 --- a/pandas/_libs/missing.pyx +++ b/pandas/_libs/missing.pyx @@ -137,7 +137,7 @@ cpdef bint is_matching_na(object left, object right, bint nan_matches_none=False return False -cpdef bint checknull(object val, bint inf_as_na=False): +cpdef bint checknull(object val): """ Return boolean describing of the input is NA-like, defined here as any of: @@ -152,8 +152,6 @@ cpdef bint checknull(object val, bint inf_as_na=False): Parameters ---------- val : object - inf_as_na : bool, default False - Whether to treat INF and -INF as NA values. Returns ------- @@ -164,8 +162,6 @@ cpdef bint checknull(object val, bint inf_as_na=False): elif util.is_float_object(val) or util.is_complex_object(val): if val != val: return True - elif inf_as_na: - return val == INF or val == NEGINF return False elif cnp.is_timedelta64_object(val): return cnp.get_timedelta64_value(val) == NPY_NAT @@ -184,7 +180,7 @@ cdef bint is_decimal_na(object val): @cython.wraparound(False) @cython.boundscheck(False) -cpdef ndarray[uint8_t] isnaobj(ndarray arr, bint inf_as_na=False): +cpdef ndarray[uint8_t] isnaobj(ndarray arr): """ Return boolean mask denoting which elements of a 1-D array are na-like, according to the criteria defined in `checknull`: @@ -217,7 +213,7 @@ cpdef ndarray[uint8_t] isnaobj(ndarray arr, bint inf_as_na=False): # equivalents to `val = values[i]` val = cnp.PyArray_GETITEM(arr, cnp.PyArray_ITER_DATA(it)) cnp.PyArray_ITER_NEXT(it) - is_null = checknull(val, inf_as_na=inf_as_na) + is_null = checknull(val) # Dereference pointer (set value) ((cnp.PyArray_ITER_DATA(it2)))[0] = is_null cnp.PyArray_ITER_NEXT(it2) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index f9e6b3296eb13..5dd1624207d41 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -406,35 +406,6 @@ def is_terminal() -> bool: with cf.config_prefix("mode"): cf.register_option("sim_interactive", False, tc_sim_interactive_doc) -use_inf_as_na_doc = """ -: boolean - True means treat None, NaN, INF, -INF as NA (old way), - False means None and NaN are null, but INF, -INF are not NA - (new way). - - This option is deprecated in pandas 2.1.0 and will be removed in 3.0. -""" - -# We don't want to start importing everything at the global context level -# or we'll hit circular deps. - - -def use_inf_as_na_cb(key) -> None: - # TODO(3.0): enforcing this deprecation will close GH#52501 - from pandas.core.dtypes.missing import _use_inf_as_na - - _use_inf_as_na(key) - - -with cf.config_prefix("mode"): - cf.register_option("use_inf_as_na", False, use_inf_as_na_doc, cb=use_inf_as_na_cb) - -cf.deprecate_option( - # GH#51684 - "mode.use_inf_as_na", - "use_inf_as_na option is deprecated and will be removed in a future " - "version. Convert inf values to NaN before operating instead.", -) # TODO better name? copy_on_write_doc = """ diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index 17c1ad5e4d8d9..9ff27bd69a1c9 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -4,7 +4,6 @@ from __future__ import annotations from decimal import Decimal -from functools import partial from typing import ( TYPE_CHECKING, overload, @@ -13,8 +12,6 @@ import numpy as np -from pandas._config import get_option - from pandas._libs import lib import pandas._libs.missing as libmissing from pandas._libs.tslibs import ( @@ -64,8 +61,6 @@ isposinf_scalar = libmissing.isposinf_scalar isneginf_scalar = libmissing.isneginf_scalar -nan_checker = np.isnan -INF_AS_NA = False _dtype_object = np.dtype("object") _dtype_str = np.dtype(str) @@ -180,86 +175,50 @@ def isna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame: isnull = isna -def _isna(obj, inf_as_na: bool = False): +def _isna(obj): """ - Detect missing values, treating None, NaN or NA as null. Infinite - values will also be treated as null if inf_as_na is True. + Detect missing values, treating None, NaN or NA as null. Parameters ---------- obj: ndarray or object value Input array or scalar value. - inf_as_na: bool - Whether to treat infinity as null. Returns ------- boolean ndarray or boolean """ if is_scalar(obj): - return libmissing.checknull(obj, inf_as_na=inf_as_na) + return libmissing.checknull(obj) elif isinstance(obj, ABCMultiIndex): raise NotImplementedError("isna is not defined for MultiIndex") elif isinstance(obj, type): return False elif isinstance(obj, (np.ndarray, ABCExtensionArray)): - return _isna_array(obj, inf_as_na=inf_as_na) + return _isna_array(obj) elif isinstance(obj, ABCIndex): # Try to use cached isna, which also short-circuits for integer dtypes # and avoids materializing RangeIndex._values if not obj._can_hold_na: return obj.isna() - return _isna_array(obj._values, inf_as_na=inf_as_na) + return _isna_array(obj._values) elif isinstance(obj, ABCSeries): - result = _isna_array(obj._values, inf_as_na=inf_as_na) + result = _isna_array(obj._values) # box result = obj._constructor(result, index=obj.index, name=obj.name, copy=False) return result elif isinstance(obj, ABCDataFrame): return obj.isna() elif isinstance(obj, list): - return _isna_array(np.asarray(obj, dtype=object), inf_as_na=inf_as_na) + return _isna_array(np.asarray(obj, dtype=object)) elif hasattr(obj, "__array__"): - return _isna_array(np.asarray(obj), inf_as_na=inf_as_na) + return _isna_array(np.asarray(obj)) else: return False -def _use_inf_as_na(key) -> None: - """ - Option change callback for na/inf behaviour. - - Choose which replacement for numpy.isnan / -numpy.isfinite is used. - - Parameters - ---------- - flag: bool - True means treat None, NaN, INF, -INF as null (old way), - False means None and NaN are null, but INF, -INF are not null - (new way). - - Notes - ----- - This approach to setting global module values is discussed and - approved here: - - * https://stackoverflow.com/questions/4859217/ - programmatically-creating-variables-in-python/4859312#4859312 - """ - inf_as_na = get_option(key) - globals()["_isna"] = partial(_isna, inf_as_na=inf_as_na) - if inf_as_na: - globals()["nan_checker"] = lambda x: ~np.isfinite(x) - globals()["INF_AS_NA"] = True - else: - globals()["nan_checker"] = np.isnan - globals()["INF_AS_NA"] = False - - -def _isna_array( - values: ArrayLike, inf_as_na: bool = False -) -> npt.NDArray[np.bool_] | NDFrame: +def _isna_array(values: ArrayLike) -> npt.NDArray[np.bool_] | NDFrame: """ Return an array indicating which values of the input array are NaN / NA. @@ -267,8 +226,6 @@ def _isna_array( ---------- obj: ndarray or ExtensionArray The input array whose elements are to be checked. - inf_as_na: bool - Whether or not to treat infinite values as NA. Returns ------- @@ -280,31 +237,25 @@ def _isna_array( if not isinstance(values, np.ndarray): # i.e. ExtensionArray - if inf_as_na and isinstance(dtype, CategoricalDtype): - result = libmissing.isnaobj(values.to_numpy(), inf_as_na=inf_as_na) - else: - # error: Incompatible types in assignment (expression has type - # "Union[ndarray[Any, Any], ExtensionArraySupportsAnyAll]", variable has - # type "ndarray[Any, dtype[bool_]]") - result = values.isna() # type: ignore[assignment] + # error: Incompatible types in assignment (expression has type + # "Union[ndarray[Any, Any], ExtensionArraySupportsAnyAll]", variable has + # type "ndarray[Any, dtype[bool_]]") + result = values.isna() # type: ignore[assignment] elif isinstance(values, np.rec.recarray): # GH 48526 - result = _isna_recarray_dtype(values, inf_as_na=inf_as_na) + result = _isna_recarray_dtype(values) elif is_string_or_object_np_dtype(values.dtype): - result = _isna_string_dtype(values, inf_as_na=inf_as_na) + result = _isna_string_dtype(values) elif dtype.kind in "mM": # this is the NaT pattern result = values.view("i8") == iNaT else: - if inf_as_na: - result = ~np.isfinite(values) - else: - result = np.isnan(values) + result = np.isnan(values) return result -def _isna_string_dtype(values: np.ndarray, inf_as_na: bool) -> npt.NDArray[np.bool_]: +def _isna_string_dtype(values: np.ndarray) -> npt.NDArray[np.bool_]: # Working around NumPy ticket 1542 dtype = values.dtype @@ -312,41 +263,21 @@ def _isna_string_dtype(values: np.ndarray, inf_as_na: bool) -> npt.NDArray[np.bo result = np.zeros(values.shape, dtype=bool) else: if values.ndim in {1, 2}: - result = libmissing.isnaobj(values, inf_as_na=inf_as_na) + result = libmissing.isnaobj(values) else: # 0-D, reached via e.g. mask_missing - result = libmissing.isnaobj(values.ravel(), inf_as_na=inf_as_na) + result = libmissing.isnaobj(values.ravel()) result = result.reshape(values.shape) return result -def _has_record_inf_value(record_as_array: np.ndarray) -> np.bool_: - is_inf_in_record = np.zeros(len(record_as_array), dtype=bool) - for i, value in enumerate(record_as_array): - is_element_inf = False - try: - is_element_inf = np.isinf(value) - except TypeError: - is_element_inf = False - is_inf_in_record[i] = is_element_inf - - return np.any(is_inf_in_record) - - -def _isna_recarray_dtype( - values: np.rec.recarray, inf_as_na: bool -) -> npt.NDArray[np.bool_]: +def _isna_recarray_dtype(values: np.rec.recarray) -> npt.NDArray[np.bool_]: result = np.zeros(values.shape, dtype=bool) for i, record in enumerate(values): record_as_array = np.array(record.tolist()) does_record_contain_nan = isna_all(record_as_array) - does_record_contain_inf = False - if inf_as_na: - does_record_contain_inf = bool(_has_record_inf_value(record_as_array)) - result[i] = np.any( - np.logical_or(does_record_contain_nan, does_record_contain_inf) - ) + result[i] = np.any(does_record_contain_nan) return result @@ -774,7 +705,7 @@ def isna_all(arr: ArrayLike) -> bool: dtype = arr.dtype if lib.is_np_dtype(dtype, "f"): - checker = nan_checker + checker = np.isnan elif (lib.is_np_dtype(dtype, "mM")) or isinstance( dtype, (DatetimeTZDtype, PeriodDtype) @@ -786,9 +717,7 @@ def isna_all(arr: ArrayLike) -> bool: else: # error: Incompatible types in assignment (expression has type "Callable[[Any], # Any]", variable has type "ufunc") - checker = lambda x: _isna_array( # type: ignore[assignment] - x, inf_as_na=INF_AS_NA - ) + checker = _isna_array # type: ignore[assignment] return all( checker(arr[i : i + chunk_len]).all() for i in range(0, total_len, chunk_len) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 93e4468f91edd..18c8b5fd51e6e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8026,8 +8026,7 @@ def isna(self) -> Self: NA values, such as None or :attr:`numpy.NaN`, gets mapped to True values. Everything else gets mapped to False values. Characters such as empty - strings ``''`` or :attr:`numpy.inf` are not considered NA values - (unless you set ``pandas.options.mode.use_inf_as_na = True``). + strings ``''`` or :attr:`numpy.inf` are not considered NA values. Returns ------- @@ -8098,8 +8097,7 @@ def notna(self) -> Self: Return a boolean same-sized object indicating if the values are not NA. Non-missing values get mapped to True. Characters such as empty - strings ``''`` or :attr:`numpy.inf` are not considered NA values - (unless you set ``pandas.options.mode.use_inf_as_na = True``). + strings ``''`` or :attr:`numpy.inf` are not considered NA values. NA values, such as None or :attr:`numpy.NaN`, get mapped to False values. diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 0fa6d2959c802..04d5fcae1a50d 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1205,10 +1205,6 @@ def _format(x): return "None" elif x is NA: return str(NA) - elif lib.is_float(x) and np.isinf(x): - # TODO(3.0): this will be unreachable when use_inf_as_na - # deprecation is enforced - return str(x) elif x is NaT or isinstance(x, (np.datetime64, np.timedelta64)): return "NaT" return self.na_rep diff --git a/pandas/tests/arrays/categorical/test_missing.py b/pandas/tests/arrays/categorical/test_missing.py index 0eeb01b746088..332d31e9e3fc2 100644 --- a/pandas/tests/arrays/categorical/test_missing.py +++ b/pandas/tests/arrays/categorical/test_missing.py @@ -8,7 +8,6 @@ import pandas as pd from pandas import ( Categorical, - DataFrame, Index, Series, isna, @@ -126,60 +125,6 @@ def test_fillna_array(self): tm.assert_categorical_equal(result, expected) assert isna(cat[-1]) # didn't modify original inplace - @pytest.mark.parametrize( - "values, expected", - [ - ([1, 2, 3], np.array([False, False, False])), - ([1, 2, np.nan], np.array([False, False, True])), - ([1, 2, np.inf], np.array([False, False, True])), - ([1, 2, pd.NA], np.array([False, False, True])), - ], - ) - def test_use_inf_as_na(self, values, expected): - # https://github.com/pandas-dev/pandas/issues/33594 - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with pd.option_context("mode.use_inf_as_na", True): - cat = Categorical(values) - result = cat.isna() - tm.assert_numpy_array_equal(result, expected) - - result = Series(cat).isna() - expected = Series(expected) - tm.assert_series_equal(result, expected) - - result = DataFrame(cat).isna() - expected = DataFrame(expected) - tm.assert_frame_equal(result, expected) - - @pytest.mark.parametrize( - "values, expected", - [ - ([1, 2, 3], np.array([False, False, False])), - ([1, 2, np.nan], np.array([False, False, True])), - ([1, 2, np.inf], np.array([False, False, True])), - ([1, 2, pd.NA], np.array([False, False, True])), - ], - ) - def test_use_inf_as_na_outside_context(self, values, expected): - # https://github.com/pandas-dev/pandas/issues/33594 - # Using isna directly for Categorical will fail in general here - cat = Categorical(values) - - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with pd.option_context("mode.use_inf_as_na", True): - result = isna(cat) - tm.assert_numpy_array_equal(result, expected) - - result = isna(Series(cat)) - expected = Series(expected) - tm.assert_series_equal(result, expected) - - result = isna(DataFrame(cat)) - expected = DataFrame(expected) - tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize( "a1, a2, categories", [ diff --git a/pandas/tests/arrays/string_/test_string.py b/pandas/tests/arrays/string_/test_string.py index cb324d29258c0..4b82d43158b88 100644 --- a/pandas/tests/arrays/string_/test_string.py +++ b/pandas/tests/arrays/string_/test_string.py @@ -597,31 +597,6 @@ def test_value_counts_sort_false(dtype): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize( - "values, expected", - [ - (["a", "b", "c"], np.array([False, False, False])), - (["a", "b", None], np.array([False, False, True])), - ], -) -def test_use_inf_as_na(values, expected, dtype): - # https://github.com/pandas-dev/pandas/issues/33655 - values = pd.array(values, dtype=dtype) - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with pd.option_context("mode.use_inf_as_na", True): - result = values.isna() - tm.assert_numpy_array_equal(result, expected) - - result = pd.Series(values).isna() - expected = pd.Series(expected) - tm.assert_series_equal(result, expected) - - result = pd.DataFrame(values).isna() - expected = pd.DataFrame(expected) - tm.assert_frame_equal(result, expected) - - def test_memory_usage(dtype, arrow_string_storage): # GH 33963 diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index c205f35b0ced8..2109c794ad44f 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -5,8 +5,6 @@ import numpy as np import pytest -from pandas._config import config as cf - from pandas._libs import missing as libmissing from pandas._libs.tslibs import iNaT from pandas.compat.numpy import np_version_gte1p25 @@ -54,25 +52,6 @@ def test_notna_notnull(notna_f): assert not notna_f(None) assert not notna_f(np.nan) - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with cf.option_context("mode.use_inf_as_na", False): - assert notna_f(np.inf) - assert notna_f(-np.inf) - - arr = np.array([1.5, np.inf, 3.5, -np.inf]) - result = notna_f(arr) - assert result.all() - - with tm.assert_produces_warning(FutureWarning, match=msg): - with cf.option_context("mode.use_inf_as_na", True): - assert not notna_f(np.inf) - assert not notna_f(-np.inf) - - arr = np.array([1.5, np.inf, 3.5, -np.inf]) - result = notna_f(arr) - assert result.sum() == 2 - @pytest.mark.parametrize("null_func", [notna, notnull, isna, isnull]) @pytest.mark.parametrize( @@ -88,10 +67,7 @@ def test_notna_notnull(notna_f): ], ) def test_null_check_is_series(null_func, ser): - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with cf.option_context("mode.use_inf_as_na", False): - assert isinstance(null_func(ser), Series) + assert isinstance(null_func(ser), Series) class TestIsNA: @@ -232,10 +208,7 @@ def test_isna_old_datetimelike(self): objs = [dta, dta.tz_localize("US/Eastern"), dta - dta, dta.to_period("D")] for obj in objs: - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with cf.option_context("mode.use_inf_as_na", True): - result = isna(obj) + result = isna(obj) tm.assert_numpy_array_equal(result, expected) @@ -743,23 +716,17 @@ class TestNAObj: def _check_behavior(self, arr, expected): result = libmissing.isnaobj(arr) tm.assert_numpy_array_equal(result, expected) - result = libmissing.isnaobj(arr, inf_as_na=True) - tm.assert_numpy_array_equal(result, expected) arr = np.atleast_2d(arr) expected = np.atleast_2d(expected) result = libmissing.isnaobj(arr) tm.assert_numpy_array_equal(result, expected) - result = libmissing.isnaobj(arr, inf_as_na=True) - tm.assert_numpy_array_equal(result, expected) # Test fortran order arr = arr.copy(order="F") result = libmissing.isnaobj(arr) tm.assert_numpy_array_equal(result, expected) - result = libmissing.isnaobj(arr, inf_as_na=True) - tm.assert_numpy_array_equal(result, expected) def test_basic(self): arr = np.array([1, None, "foo", -5.1, NaT, np.nan]) @@ -868,19 +835,11 @@ def test_checknull_never_na_vals(self, func, value): na_vals + sometimes_na_vals, # type: ignore[operator] ) def test_checknull_old_na_vals(self, value): - assert libmissing.checknull(value, inf_as_na=True) - - @pytest.mark.parametrize("value", inf_vals) - def test_checknull_old_inf_vals(self, value): - assert libmissing.checknull(value, inf_as_na=True) + assert libmissing.checknull(value) @pytest.mark.parametrize("value", int_na_vals) def test_checknull_old_intna_vals(self, value): - assert not libmissing.checknull(value, inf_as_na=True) - - @pytest.mark.parametrize("value", int_na_vals) - def test_checknull_old_never_na_vals(self, value): - assert not libmissing.checknull(value, inf_as_na=True) + assert not libmissing.checknull(value) def test_is_matching_na(self, nulls_fixture, nulls_fixture2): left = nulls_fixture diff --git a/pandas/tests/extension/base/missing.py b/pandas/tests/extension/base/missing.py index dbd6682c12123..b9cba2fc52728 100644 --- a/pandas/tests/extension/base/missing.py +++ b/pandas/tests/extension/base/missing.py @@ -177,12 +177,3 @@ def test_fillna_fill_other(self, data): expected = pd.DataFrame({"A": data, "B": [0.0] * len(result)}) tm.assert_frame_equal(result, expected) - - def test_use_inf_as_na_no_effect(self, data_missing): - ser = pd.Series(data_missing) - expected = ser.isna() - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with pd.option_context("mode.use_inf_as_na", True): - result = ser.isna() - tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_dtypes.py b/pandas/tests/frame/methods/test_dtypes.py index ab632ac17318e..0697f59cd271f 100644 --- a/pandas/tests/frame/methods/test_dtypes.py +++ b/pandas/tests/frame/methods/test_dtypes.py @@ -10,7 +10,6 @@ DataFrame, Series, date_range, - option_context, ) import pandas._testing as tm @@ -95,14 +94,6 @@ def test_dtypes_gh8722(self, float_string_frame): ) tm.assert_series_equal(result, expected) - # compat, GH 8722 - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with option_context("use_inf_as_na", True): - df = DataFrame([[1]]) - result = df.dtypes - tm.assert_series_equal(result, Series({0: np.dtype("int64")})) - def test_dtypes_timedeltas(self): df = DataFrame( { diff --git a/pandas/tests/frame/methods/test_sort_index.py b/pandas/tests/frame/methods/test_sort_index.py index d88daaff685aa..1a631e760208a 100644 --- a/pandas/tests/frame/methods/test_sort_index.py +++ b/pandas/tests/frame/methods/test_sort_index.py @@ -773,18 +773,6 @@ def test_sort_index_ascending_bad_value_raises(self, ascending): with pytest.raises(ValueError, match=match): df.sort_index(axis=0, ascending=ascending, na_position="first") - def test_sort_index_use_inf_as_na(self): - # GH 29687 - expected = DataFrame( - {"col1": [1, 2, 3], "col2": [3, 4, 5]}, - index=pd.date_range("2020", periods=3), - ) - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with pd.option_context("mode.use_inf_as_na", True): - result = expected.sort_index() - tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize( "ascending", [(True, False), [True, False]], diff --git a/pandas/tests/frame/test_repr.py b/pandas/tests/frame/test_repr.py index 4425d067e67dc..f6e0251d52de1 100644 --- a/pandas/tests/frame/test_repr.py +++ b/pandas/tests/frame/test_repr.py @@ -425,38 +425,18 @@ def test_to_records_with_na_record(self): result = repr(df) assert result == expected - def test_to_records_with_inf_as_na_record(self): - # GH 48526 - expected = """ NaN inf record -0 inf b [0, inf, b] -1 NaN NaN [1, nan, nan] -2 e f [2, e, f]""" - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with option_context("use_inf_as_na", True): - df = DataFrame( - [[np.inf, "b"], [np.nan, np.nan], ["e", "f"]], - columns=[np.nan, np.inf], - ) - df["record"] = df[[np.nan, np.inf]].to_records() - result = repr(df) - assert result == expected - def test_to_records_with_inf_record(self): # GH 48526 expected = """ NaN inf record 0 inf b [0, inf, b] 1 NaN NaN [1, nan, nan] 2 e f [2, e, f]""" - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with option_context("use_inf_as_na", False): - df = DataFrame( - [[np.inf, "b"], [np.nan, np.nan], ["e", "f"]], - columns=[np.nan, np.inf], - ) - df["record"] = df[[np.nan, np.inf]].to_records() - result = repr(df) + df = DataFrame( + [[np.inf, "b"], [np.nan, np.nan], ["e", "f"]], + columns=[np.nan, np.inf], + ) + df["record"] = df[[np.nan, np.inf]].to_records() + result = repr(df) assert result == expected def test_masked_ea_with_formatter(self): diff --git a/pandas/tests/io/parser/common/test_inf.py b/pandas/tests/io/parser/common/test_inf.py index 74596b178d35d..dba952b1f9ebd 100644 --- a/pandas/tests/io/parser/common/test_inf.py +++ b/pandas/tests/io/parser/common/test_inf.py @@ -4,13 +4,9 @@ """ from io import StringIO -import numpy as np import pytest -from pandas import ( - DataFrame, - option_context, -) +from pandas import DataFrame import pandas._testing as tm pytestmark = pytest.mark.filterwarnings( @@ -60,19 +56,3 @@ def test_infinity_parsing(all_parsers, na_filter): ) result = parser.read_csv(StringIO(data), index_col=0, na_filter=na_filter) tm.assert_frame_equal(result, expected) - - -def test_read_csv_with_use_inf_as_na(all_parsers): - # https://github.com/pandas-dev/pandas/issues/35493 - parser = all_parsers - data = "1.0\nNaN\n3.0" - msg = "use_inf_as_na option is deprecated" - warn = FutureWarning - if parser.engine == "pyarrow": - warn = (FutureWarning, DeprecationWarning) - - with tm.assert_produces_warning(warn, match=msg, check_stacklevel=False): - with option_context("use_inf_as_na", True): - result = parser.read_csv(StringIO(data), header=None) - expected = DataFrame([1.0, np.nan, 3.0]) - tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index efecd43625eed..91ee13ecd87dd 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -594,11 +594,6 @@ def test_sum_inf(self): arr = np.random.default_rng(2).standard_normal((100, 100)).astype("f4") arr[:, 2] = np.inf - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with pd.option_context("mode.use_inf_as_na", True): - tm.assert_almost_equal(s.sum(), s2.sum()) - res = nanops.nansum(arr, axis=1) assert np.isinf(res).all() @@ -1242,16 +1237,6 @@ def test_idxminmax_with_inf(self): with tm.assert_produces_warning(FutureWarning, match=msg): assert np.isnan(s.idxmax(skipna=False)) - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - # Using old-style behavior that treats floating point nan, -inf, and - # +inf as missing - with pd.option_context("mode.use_inf_as_na", True): - assert s.idxmin() == 0 - assert np.isnan(s.idxmin(skipna=False)) - assert s.idxmax() == 0 - np.isnan(s.idxmax(skipna=False)) - def test_sum_uint64(self): # GH 53401 s = Series([10000000000000000000], dtype="uint64") diff --git a/pandas/tests/series/methods/test_count.py b/pandas/tests/series/methods/test_count.py index 9ba163f347198..2172a3205ef55 100644 --- a/pandas/tests/series/methods/test_count.py +++ b/pandas/tests/series/methods/test_count.py @@ -1,11 +1,9 @@ import numpy as np -import pandas as pd from pandas import ( Categorical, Series, ) -import pandas._testing as tm class TestSeriesCount: @@ -16,14 +14,6 @@ def test_count(self, datetime_series): assert datetime_series.count() == np.isfinite(datetime_series).sum() - def test_count_inf_as_na(self): - # GH#29478 - ser = Series([pd.Timestamp("1990/1/1")]) - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with pd.option_context("use_inf_as_na", True): - assert ser.count() == 1 - def test_count_categorical(self): ser = Series( Categorical( diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index cafc69c4d0f20..108c3aabb1aa4 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -25,18 +25,6 @@ def test_categorical_nan_handling(self): s.values.codes, np.array([0, 1, -1, 0], dtype=np.int8) ) - def test_isna_for_inf(self): - s = Series(["a", np.inf, np.nan, pd.NA, 1.0]) - msg = "use_inf_as_na option is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - with pd.option_context("mode.use_inf_as_na", True): - r = s.isna() - dr = s.dropna() - e = Series([False, True, True, True, False]) - de = Series(["a", 1.0], index=[0, 4]) - tm.assert_series_equal(r, e) - tm.assert_series_equal(dr, de) - def test_timedelta64_nan(self): td = Series([timedelta(days=i) for i in range(10)]) diff --git a/scripts/validate_unwanted_patterns.py b/scripts/validate_unwanted_patterns.py index fd8963ad85abc..a732d3f83a40a 100755 --- a/scripts/validate_unwanted_patterns.py +++ b/scripts/validate_unwanted_patterns.py @@ -35,7 +35,6 @@ "_apply_groupings_depr", "__main__", "_transform_template", - "_use_inf_as_na", "_get_plot_backend", "_matplotlib", "_arrow_utils",