diff --git a/asv_bench/benchmarks/algos/isin.py b/asv_bench/benchmarks/algos/isin.py index ac79ab65cea81..92797425b2c30 100644 --- a/asv_bench/benchmarks/algos/isin.py +++ b/asv_bench/benchmarks/algos/isin.py @@ -247,7 +247,7 @@ def setup(self, series_type, vals_type): elif series_type == "long": ser_vals = np.arange(N_many) elif series_type == "long_floats": - ser_vals = np.arange(N_many, dtype=np.float_) + ser_vals = np.arange(N_many, dtype=np.float64) self.series = Series(ser_vals).astype(object) @@ -258,7 +258,7 @@ def setup(self, series_type, vals_type): elif vals_type == "long": values = np.arange(N_many) elif vals_type == "long_floats": - values = np.arange(N_many, dtype=np.float_) + values = np.arange(N_many, dtype=np.float64) self.values = values.astype(object) diff --git a/doc/source/getting_started/comparison/comparison_with_sql.rst b/doc/source/getting_started/comparison/comparison_with_sql.rst index 7a83d50416186..f0eaa7362c52c 100644 --- a/doc/source/getting_started/comparison/comparison_with_sql.rst +++ b/doc/source/getting_started/comparison/comparison_with_sql.rst @@ -107,7 +107,7 @@ methods. .. ipython:: python frame = pd.DataFrame( - {"col1": ["A", "B", np.NaN, "C", "D"], "col2": ["F", np.NaN, "G", "H", "I"]} + {"col1": ["A", "B", np.nan, "C", "D"], "col2": ["F", np.nan, "G", "H", "I"]} ) frame diff --git a/doc/source/user_guide/enhancingperf.rst b/doc/source/user_guide/enhancingperf.rst index 2ddc3e709be85..bc2f4420da784 100644 --- a/doc/source/user_guide/enhancingperf.rst +++ b/doc/source/user_guide/enhancingperf.rst @@ -183,8 +183,8 @@ can be improved by passing an ``np.ndarray``. ...: return s * dx ...: cpdef np.ndarray[double] apply_integrate_f(np.ndarray col_a, np.ndarray col_b, ...: np.ndarray col_N): - ...: assert (col_a.dtype == np.float_ - ...: and col_b.dtype == np.float_ and col_N.dtype == np.int_) + ...: assert (col_a.dtype == np.float64 + ...: and col_b.dtype == np.float64 and col_N.dtype == np.int_) ...: cdef Py_ssize_t i, n = len(col_N) ...: assert (len(col_a) == len(col_b) == n) ...: cdef np.ndarray[double] res = np.empty(n) diff --git a/doc/source/user_guide/gotchas.rst b/doc/source/user_guide/gotchas.rst index 67106df328361..c00a236ff4e9d 100644 --- a/doc/source/user_guide/gotchas.rst +++ b/doc/source/user_guide/gotchas.rst @@ -327,7 +327,7 @@ present in the more domain-specific statistical programming language `R ``numpy.unsignedinteger`` | ``uint8, uint16, uint32, uint64`` ``numpy.object_`` | ``object_`` ``numpy.bool_`` | ``bool_`` - ``numpy.character`` | ``string_, unicode_`` + ``numpy.character`` | ``bytes_, str_`` The R language, by contrast, only has a handful of built-in data types: ``integer``, ``numeric`` (floating-point), ``character``, and diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 6e352c52cd60e..df2f1bccc3cff 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -4881,7 +4881,7 @@ unspecified columns of the given DataFrame. The argument ``selector`` defines which table is the selector table (which you can make queries from). The argument ``dropna`` will drop rows from the input ``DataFrame`` to ensure tables are synchronized. This means that if a row for one of the tables -being written to is entirely ``np.NaN``, that row will be dropped from all tables. +being written to is entirely ``np.nan``, that row will be dropped from all tables. If ``dropna`` is False, **THE USER IS RESPONSIBLE FOR SYNCHRONIZING THE TABLES**. Remember that entirely ``np.Nan`` rows are not written to the HDFStore, so if diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 73a523b14f9f7..38c6e1123aaae 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -556,7 +556,7 @@ You must pass in the ``line_terminator`` explicitly, even in this case. .. _whatsnew_0240.bug_fixes.nan_with_str_dtype: -Proper handling of ``np.NaN`` in a string data-typed column with the Python engine +Proper handling of ``np.nan`` in a string data-typed column with the Python engine ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ There was bug in :func:`read_excel` and :func:`read_csv` with the Python diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index 0b6ea58f987d4..9eed70a23c9dd 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -59,7 +59,7 @@ from pandas._libs.util cimport get_nat cdef: float64_t FP_ERR = 1e-13 - float64_t NaN = np.NaN + float64_t NaN = np.nan int64_t NPY_NAT = get_nat() diff --git a/pandas/_libs/groupby.pyx b/pandas/_libs/groupby.pyx index 20499016f951e..7635b261d4149 100644 --- a/pandas/_libs/groupby.pyx +++ b/pandas/_libs/groupby.pyx @@ -52,7 +52,7 @@ from pandas._libs.missing cimport checknull cdef int64_t NPY_NAT = util.get_nat() -cdef float64_t NaN = np.NaN +cdef float64_t NaN = np.nan cdef enum InterpolationEnumType: INTERPOLATION_LINEAR, diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index a96152ccdf3cc..2681115bbdcfb 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -144,7 +144,7 @@ cdef: object oINT64_MIN = INT64_MIN object oUINT64_MAX = UINT64_MAX - float64_t NaN = np.NaN + float64_t NaN = np.nan # python-visible i8max = INT64_MAX diff --git a/pandas/_libs/tslibs/util.pxd b/pandas/_libs/tslibs/util.pxd index e25e7e8b94e1d..519d3fc939efa 100644 --- a/pandas/_libs/tslibs/util.pxd +++ b/pandas/_libs/tslibs/util.pxd @@ -75,7 +75,7 @@ cdef inline bint is_integer_object(object obj) noexcept nogil: cdef inline bint is_float_object(object obj) noexcept nogil: """ - Cython equivalent of `isinstance(val, (float, np.float_))` + Cython equivalent of `isinstance(val, (float, np.float64))` Parameters ---------- @@ -91,7 +91,7 @@ cdef inline bint is_float_object(object obj) noexcept nogil: cdef inline bint is_complex_object(object obj) noexcept nogil: """ - Cython equivalent of `isinstance(val, (complex, np.complex_))` + Cython equivalent of `isinstance(val, (complex, np.complex128))` Parameters ---------- diff --git a/pandas/_libs/window/aggregations.pyx b/pandas/_libs/window/aggregations.pyx index 425c5ade2e2d4..9c151b8269a52 100644 --- a/pandas/_libs/window/aggregations.pyx +++ b/pandas/_libs/window/aggregations.pyx @@ -57,7 +57,7 @@ cdef: float32_t MAXfloat32 = np.inf float64_t MAXfloat64 = np.inf - float64_t NaN = np.NaN + float64_t NaN = np.nan cdef bint is_monotonic_increasing_start_end_bounds( ndarray[int64_t, ndim=1] start, ndarray[int64_t, ndim=1] end diff --git a/pandas/conftest.py b/pandas/conftest.py index f756da82157b8..757ca817d1b85 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -777,7 +777,7 @@ def series_with_multilevel_index() -> Series: index = MultiIndex.from_tuples(tuples) data = np.random.default_rng(2).standard_normal(8) ser = Series(data, index=index) - ser.iloc[3] = np.NaN + ser.iloc[3] = np.nan return ser diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 6107388bfe78b..aefc94ebd665c 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2109,7 +2109,7 @@ def _codes(self) -> np.ndarray: def _box_func(self, i: int): if i == -1: - return np.NaN + return np.nan return self.categories[i] def _unbox_scalar(self, key) -> int: diff --git a/pandas/core/computation/ops.py b/pandas/core/computation/ops.py index 9050fb6e76b9c..852bfae1cc79a 100644 --- a/pandas/core/computation/ops.py +++ b/pandas/core/computation/ops.py @@ -537,8 +537,8 @@ def __init__(self, lhs, rhs) -> None: ) # do not upcast float32s to float64 un-necessarily - acceptable_dtypes = [np.float32, np.float_] - _cast_inplace(com.flatten(self), acceptable_dtypes, np.float_) + acceptable_dtypes = [np.float32, np.float64] + _cast_inplace(com.flatten(self), acceptable_dtypes, np.float64) UNARY_OPS_SYMS = ("+", "-", "~", "not") diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 9f7c0b3e36032..657cbce40087a 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -850,7 +850,7 @@ def infer_dtype_from_scalar(val) -> tuple[DtypeObj, Any]: dtype = np.dtype(np.float64) elif is_complex(val): - dtype = np.dtype(np.complex_) + dtype = np.dtype(np.complex128) if lib.is_period(val): dtype = PeriodDtype(freq=val.freq) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index a0feb49f47c4e..c2e498e75b7d3 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1351,7 +1351,7 @@ def is_complex_dtype(arr_or_dtype) -> bool: False >>> is_complex_dtype(int) False - >>> is_complex_dtype(np.complex_) + >>> is_complex_dtype(np.complex128) True >>> is_complex_dtype(np.array(['a', 'b'])) False diff --git a/pandas/core/generic.py b/pandas/core/generic.py index be0d046697ba9..954573febed41 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5307,7 +5307,7 @@ def reindex( level : int or name Broadcast across a level, matching Index values on the passed MultiIndex level. - fill_value : scalar, default np.NaN + fill_value : scalar, default np.nan Value to use for missing values. Defaults to NaN, but can be any "compatible" value. limit : int, default None @@ -7376,7 +7376,7 @@ def ffill( 2 3.0 4.0 NaN 1.0 3 3.0 3.0 NaN 4.0 - >>> ser = pd.Series([1, np.NaN, 2, 3]) + >>> ser = pd.Series([1, np.nan, 2, 3]) >>> ser.ffill() 0 1.0 1 1.0 @@ -8375,7 +8375,7 @@ def isna(self) -> Self: -------- Show which entries in a DataFrame are NA. - >>> df = pd.DataFrame(dict(age=[5, 6, np.NaN], + >>> df = pd.DataFrame(dict(age=[5, 6, np.nan], ... born=[pd.NaT, pd.Timestamp('1939-05-27'), ... pd.Timestamp('1940-04-25')], ... name=['Alfred', 'Batman', ''], @@ -8394,7 +8394,7 @@ def isna(self) -> Self: Show which entries in a Series are NA. - >>> ser = pd.Series([5, 6, np.NaN]) + >>> ser = pd.Series([5, 6, np.nan]) >>> ser 0 5.0 1 6.0 @@ -8442,7 +8442,7 @@ def notna(self) -> Self: -------- Show which entries in a DataFrame are not NA. - >>> df = pd.DataFrame(dict(age=[5, 6, np.NaN], + >>> df = pd.DataFrame(dict(age=[5, 6, np.nan], ... born=[pd.NaT, pd.Timestamp('1939-05-27'), ... pd.Timestamp('1940-04-25')], ... name=['Alfred', 'Batman', ''], @@ -8461,7 +8461,7 @@ def notna(self) -> Self: Show which entries in a Series are not NA. - >>> ser = pd.Series([5, 6, np.NaN]) + >>> ser = pd.Series([5, 6, np.nan]) >>> ser 0 5.0 1 6.0 @@ -8628,7 +8628,7 @@ def clip( Clips using specific lower threshold per column element, with missing values: - >>> t = pd.Series([2, -4, np.NaN, 6, 3]) + >>> t = pd.Series([2, -4, np.nan, 6, 3]) >>> t 0 2.0 1 -4.0 @@ -9828,7 +9828,7 @@ def align( copy : bool, default True Always returns new objects. If copy=False and no reindexing is required then original objects are returned. - fill_value : scalar, default np.NaN + fill_value : scalar, default np.nan Value to use for missing values. Defaults to NaN, but can be any "compatible" value. method : {{'backfill', 'bfill', 'pad', 'ffill', None}}, default None diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index e327dd9d6c5ff..5a7f42a535951 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -5418,7 +5418,7 @@ def _mask_selected_obj(self, mask: npt.NDArray[np.bool_]) -> NDFrameT: def _reindex_output( self, output: OutputFrameOrSeries, - fill_value: Scalar = np.NaN, + fill_value: Scalar = np.nan, qs: npt.NDArray[np.float64] | None = None, ) -> OutputFrameOrSeries: """ @@ -5436,7 +5436,7 @@ def _reindex_output( ---------- output : Series or DataFrame Object resulting from grouping and applying an operation. - fill_value : scalar, default np.NaN + fill_value : scalar, default np.nan Value to use for unobserved categories if self.observed is False. qs : np.ndarray[float64] or None, default None quantile values, only relevant for quantile. diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index dbb7cb97d1d6f..5854342cdcf13 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2854,7 +2854,7 @@ def isna(self) -> npt.NDArray[np.bool_]: Show which entries in a pandas.Index are NA. The result is an array. - >>> idx = pd.Index([5.2, 6.0, np.NaN]) + >>> idx = pd.Index([5.2, 6.0, np.nan]) >>> idx Index([5.2, 6.0, nan], dtype='float64') >>> idx.isna() @@ -2910,7 +2910,7 @@ def notna(self) -> npt.NDArray[np.bool_]: Show which entries in an Index are not NA. The result is an array. - >>> idx = pd.Index([5.2, 6.0, np.NaN]) + >>> idx = pd.Index([5.2, 6.0, np.nan]) >>> idx Index([5.2, 6.0, nan], dtype='float64') >>> idx.notna() diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 302d8fdb353fd..b36672df32e61 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -125,7 +125,7 @@ def _get_next_label(label): elif is_integer_dtype(dtype): return label + 1 elif is_float_dtype(dtype): - return np.nextafter(label, np.infty) + return np.nextafter(label, np.inf) else: raise TypeError(f"cannot determine next label for type {repr(type(label))}") @@ -142,7 +142,7 @@ def _get_prev_label(label): elif is_integer_dtype(dtype): return label - 1 elif is_float_dtype(dtype): - return np.nextafter(label, -np.infty) + return np.nextafter(label, -np.inf) else: raise TypeError(f"cannot determine next label for type {repr(type(label))}") diff --git a/pandas/core/series.py b/pandas/core/series.py index 020fadc359ebd..d7258cd1cf4b2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -5586,7 +5586,7 @@ def dropna( Empty strings are not considered NA values. ``None`` is considered an NA value. - >>> ser = pd.Series([np.NaN, 2, pd.NaT, '', None, 'I stay']) + >>> ser = pd.Series([np.nan, 2, pd.NaT, '', None, 'I stay']) >>> ser 0 NaN 1 2 diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index e59369db776da..becf9b47b3af1 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -1215,7 +1215,7 @@ def contains( -------- Returning a Series of booleans using only a literal pattern. - >>> s1 = pd.Series(['Mouse', 'dog', 'house and parrot', '23', np.NaN]) + >>> s1 = pd.Series(['Mouse', 'dog', 'house and parrot', '23', np.nan]) >>> s1.str.contains('og', regex=False) 0 False 1 True @@ -1226,7 +1226,7 @@ def contains( Returning an Index of booleans using only a literal pattern. - >>> ind = pd.Index(['Mouse', 'dog', 'house and parrot', '23.0', np.NaN]) + >>> ind = pd.Index(['Mouse', 'dog', 'house and parrot', '23.0', np.nan]) >>> ind.str.contains('23', regex=False) Index([False, False, False, True, nan], dtype='object') @@ -3500,7 +3500,7 @@ def str_extractall(arr, pat, flags: int = 0) -> DataFrame: for match_i, match_tuple in enumerate(regex.findall(subject)): if isinstance(match_tuple, str): match_tuple = (match_tuple,) - na_tuple = [np.NaN if group == "" else group for group in match_tuple] + na_tuple = [np.nan if group == "" else group for group in match_tuple] match_list.append(na_tuple) result_key = tuple(subject_key + (match_i,)) index_list.append(result_key) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 9fe8cbfa159c6..ff26abd5cc26c 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1715,7 +1715,7 @@ def format_percentiles( """ percentiles = np.asarray(percentiles) - # It checks for np.NaN as well + # It checks for np.nan as well if ( not is_numeric_dtype(percentiles) or not np.all(percentiles >= 0) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index ba052c6936dd9..3a3f73a68374b 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -637,15 +637,15 @@ def test_apply_with_byte_string(): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("val", ["asd", 12, None, np.NaN]) +@pytest.mark.parametrize("val", ["asd", 12, None, np.nan]) def test_apply_category_equalness(val): # Check if categorical comparisons on apply, GH 21239 - df_values = ["asd", None, 12, "asd", "cde", np.NaN] + df_values = ["asd", None, 12, "asd", "cde", np.nan] df = DataFrame({"a": df_values}, dtype="category") result = df.a.apply(lambda x: x == val) expected = Series( - [np.NaN if pd.isnull(x) else x == val for x in df_values], name="a" + [np.nan if pd.isnull(x) else x == val for x in df_values], name="a" ) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/apply/test_series_apply.py b/pandas/tests/apply/test_series_apply.py index aea1e03dfe0ee..d3e5ac1b4ca7a 100644 --- a/pandas/tests/apply/test_series_apply.py +++ b/pandas/tests/apply/test_series_apply.py @@ -242,7 +242,7 @@ def test_apply_categorical(by_row): assert result.dtype == object -@pytest.mark.parametrize("series", [["1-1", "1-1", np.NaN], ["1-1", "1-2", np.NaN]]) +@pytest.mark.parametrize("series", [["1-1", "1-1", np.nan], ["1-1", "1-2", np.nan]]) def test_apply_categorical_with_nan_values(series, by_row): # GH 20714 bug fixed in: GH 24275 s = Series(series, dtype="category") @@ -254,7 +254,7 @@ def test_apply_categorical_with_nan_values(series, by_row): result = s.apply(lambda x: x.split("-")[0], by_row=by_row) result = result.astype(object) - expected = Series(["1", "1", np.NaN], dtype="category") + expected = Series(["1", "1", np.nan], dtype="category") expected = expected.astype(object) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/arrays/categorical/test_analytics.py b/pandas/tests/arrays/categorical/test_analytics.py index c42364d4d4377..c2c53fbc4637e 100644 --- a/pandas/tests/arrays/categorical/test_analytics.py +++ b/pandas/tests/arrays/categorical/test_analytics.py @@ -73,8 +73,8 @@ def test_min_max_reduce(self): @pytest.mark.parametrize( "categories,expected", [ - (list("ABC"), np.NaN), - ([1, 2, 3], np.NaN), + (list("ABC"), np.nan), + ([1, 2, 3], np.nan), pytest.param( Series(date_range("2020-01-01", periods=3), dtype="category"), NaT, diff --git a/pandas/tests/arrays/interval/test_interval.py b/pandas/tests/arrays/interval/test_interval.py index e16ef37e8799d..761b85287764f 100644 --- a/pandas/tests/arrays/interval/test_interval.py +++ b/pandas/tests/arrays/interval/test_interval.py @@ -129,7 +129,7 @@ def test_set_na(self, left_right_dtypes): # GH#45484 TypeError, not ValueError, matches what we get with # non-NA un-holdable value. with pytest.raises(TypeError, match=msg): - result[0] = np.NaN + result[0] = np.nan return result[0] = np.nan diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index f958d25e51103..9c630e29ea8e6 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -725,7 +725,7 @@ def test_and_logic_string_match(self): class TestTypeCasting: @pytest.mark.parametrize("op", ["+", "-", "*", "**", "/"]) # maybe someday... numexpr has too many upcasting rules now - # chain(*(np.sctypes[x] for x in ['uint', 'int', 'float'])) + # chain(*(np.core.sctypes[x] for x in ['uint', 'int', 'float'])) @pytest.mark.parametrize("dt", [np.float32, np.float64]) @pytest.mark.parametrize("left_right", [("df", "3"), ("3", "df")]) def test_binop_typecasting(self, engine, parser, op, dt, left_right): diff --git a/pandas/tests/dtypes/cast/test_infer_dtype.py b/pandas/tests/dtypes/cast/test_infer_dtype.py index b5d761b3549fa..ed08df74461ef 100644 --- a/pandas/tests/dtypes/cast/test_infer_dtype.py +++ b/pandas/tests/dtypes/cast/test_infer_dtype.py @@ -42,7 +42,7 @@ def test_infer_dtype_from_float_scalar(float_numpy_dtype): @pytest.mark.parametrize( - "data,exp_dtype", [(12, np.int64), (np.float_(12), np.float64)] + "data,exp_dtype", [(12, np.int64), (np.float64(12), np.float64)] ) def test_infer_dtype_from_python_scalar(data, exp_dtype): dtype, val = infer_dtype_from_scalar(data) @@ -58,7 +58,7 @@ def test_infer_dtype_from_boolean(bool_val): def test_infer_dtype_from_complex(complex_dtype): data = np.dtype(complex_dtype).type(1) dtype, val = infer_dtype_from_scalar(data) - assert dtype == np.complex_ + assert dtype == np.complex128 def test_infer_dtype_from_datetime(): @@ -153,7 +153,7 @@ def test_infer_dtype_from_scalar_errors(): ("foo", np.object_), (b"foo", np.object_), (1, np.int64), - (1.5, np.float_), + (1.5, np.float64), (np.datetime64("2016-01-01"), np.dtype("M8[s]")), (Timestamp("20160101"), np.dtype("M8[s]")), (Timestamp("20160101", tz="UTC"), "datetime64[s, UTC]"), @@ -173,7 +173,7 @@ def test_infer_dtype_from_scalar(value, expected): ([1], np.int_), (np.array([1], dtype=np.int64), np.int64), ([np.nan, 1, ""], np.object_), - (np.array([[1.0, 2.0]]), np.float_), + (np.array([[1.0, 2.0]]), np.float64), (Categorical(list("aabc")), "category"), (Categorical([1, 2, 3]), "category"), (date_range("20160101", periods=3), np.dtype("=M8[ns]")), diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 0043ace1b9590..471e456146178 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -652,7 +652,7 @@ def test_is_complex_dtype(): assert not com.is_complex_dtype(pd.Series([1, 2])) assert not com.is_complex_dtype(np.array(["a", "b"])) - assert com.is_complex_dtype(np.complex_) + assert com.is_complex_dtype(np.complex128) assert com.is_complex_dtype(complex) assert com.is_complex_dtype(np.array([1 + 1j, 5])) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 375003e58c21a..df7c787d2b9bf 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -536,7 +536,7 @@ def test_isneginf_scalar(self, value, expected): ) def test_maybe_convert_nullable_boolean(self, convert_to_masked_nullable, exp): # GH 40687 - arr = np.array([True, np.NaN], dtype=object) + arr = np.array([True, np.nan], dtype=object) result = libops.maybe_convert_bool( arr, set(), convert_to_masked_nullable=convert_to_masked_nullable ) @@ -862,7 +862,7 @@ def test_maybe_convert_objects_timedelta64_nat(self): ) def test_maybe_convert_objects_nullable_integer(self, exp): # GH27335 - arr = np.array([2, np.NaN], dtype=object) + arr = np.array([2, np.nan], dtype=object) result = lib.maybe_convert_objects(arr, convert_to_nullable_dtype=True) tm.assert_extension_array_equal(result, exp) @@ -890,7 +890,7 @@ def test_maybe_convert_numeric_nullable_integer( self, convert_to_masked_nullable, exp ): # GH 40687 - arr = np.array([2, np.NaN], dtype=object) + arr = np.array([2, np.nan], dtype=object) result = lib.maybe_convert_numeric( arr, set(), convert_to_masked_nullable=convert_to_masked_nullable ) @@ -1889,7 +1889,6 @@ def test_is_scalar_numpy_array_scalars(self): assert is_scalar(np.complex64(2)) assert is_scalar(np.object_("foobar")) assert is_scalar(np.str_("foobar")) - assert is_scalar(np.unicode_("foobar")) assert is_scalar(np.bytes_(b"foobar")) assert is_scalar(np.datetime64("2014-01-01")) assert is_scalar(np.timedelta64(1, "h")) diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index 170f4f49ba377..451ac2afd1d91 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -51,7 +51,7 @@ def test_notna_notnull(notna_f): assert notna_f(1.0) assert not notna_f(None) - assert not notna_f(np.NaN) + assert not notna_f(np.nan) msg = "use_inf_as_na option is deprecated" with tm.assert_produces_warning(FutureWarning, match=msg): @@ -112,7 +112,7 @@ def test_empty_object(self, shape): def test_isna_isnull(self, isna_f): assert not isna_f(1.0) assert isna_f(None) - assert isna_f(np.NaN) + assert isna_f(np.nan) assert float("nan") assert not isna_f(np.inf) assert not isna_f(-np.inf) @@ -156,7 +156,7 @@ def test_isna_lists(self): tm.assert_numpy_array_equal(result, exp) # GH20675 - result = isna([np.NaN, "world"]) + result = isna([np.nan, "world"]) exp = np.array([True, False]) tm.assert_numpy_array_equal(result, exp) diff --git a/pandas/tests/frame/constructors/test_from_records.py b/pandas/tests/frame/constructors/test_from_records.py index 95f9f2ba4051e..59dca5055f170 100644 --- a/pandas/tests/frame/constructors/test_from_records.py +++ b/pandas/tests/frame/constructors/test_from_records.py @@ -269,7 +269,7 @@ def test_from_records_series_categorical_index(self): series_of_dicts = Series([{"a": 1}, {"a": 2}, {"b": 3}], index=index) frame = DataFrame.from_records(series_of_dicts, index=index) expected = DataFrame( - {"a": [1, 2, np.NaN], "b": [np.NaN, np.NaN, 3]}, index=index + {"a": [1, 2, np.nan], "b": [np.nan, np.nan, 3]}, index=index ) tm.assert_frame_equal(frame, expected) diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index 34cbebe1b3d3f..6590f10c6b967 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -164,7 +164,7 @@ def test_astype_str(self): def test_astype_str_float(self): # see GH#11302 - result = DataFrame([np.NaN]).astype(str) + result = DataFrame([np.nan]).astype(str) expected = DataFrame(["nan"]) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_clip.py b/pandas/tests/frame/methods/test_clip.py index 710978057460a..9bd032a0aefc4 100644 --- a/pandas/tests/frame/methods/test_clip.py +++ b/pandas/tests/frame/methods/test_clip.py @@ -166,7 +166,7 @@ def test_clip_with_na_args(self, float_frame): # GH#40420 data = {"col_0": [9, -3, 0, -1, 5], "col_1": [-2, -7, 6, 8, -5]} df = DataFrame(data) - t = Series([2, -4, np.NaN, 6, 3]) + t = Series([2, -4, np.nan, 6, 3]) result = df.clip(lower=t, axis=0) expected = DataFrame({"col_0": [9, -3, 0, 6, 5], "col_1": [2, -4, 6, 8, 3]}) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_describe.py b/pandas/tests/frame/methods/test_describe.py index e2f92a1e04cb5..f56a7896c753e 100644 --- a/pandas/tests/frame/methods/test_describe.py +++ b/pandas/tests/frame/methods/test_describe.py @@ -332,7 +332,7 @@ def test_describe_percentiles_integer_idx(self): result = df.describe(percentiles=pct) expected = DataFrame( - {"x": [1.0, 1.0, np.NaN, 1.0, *(1.0 for _ in pct), 1.0]}, + {"x": [1.0, 1.0, np.nan, 1.0, *(1.0 for _ in pct), 1.0]}, index=[ "count", "mean", diff --git a/pandas/tests/frame/methods/test_dropna.py b/pandas/tests/frame/methods/test_dropna.py index 11edf665b5494..7899b4aeac3fd 100644 --- a/pandas/tests/frame/methods/test_dropna.py +++ b/pandas/tests/frame/methods/test_dropna.py @@ -231,7 +231,7 @@ def test_dropna_with_duplicate_columns(self): def test_set_single_column_subset(self): # GH 41021 - df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.NaN, 5]}) + df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.nan, 5]}) expected = DataFrame( {"A": [1, 3], "B": list("ac"), "C": [4.0, 5.0]}, index=[0, 2] ) @@ -248,7 +248,7 @@ def test_single_column_not_present_in_axis(self): def test_subset_is_nparray(self): # GH 41021 - df = DataFrame({"A": [1, 2, np.NaN], "B": list("abc"), "C": [4, np.NaN, 5]}) + df = DataFrame({"A": [1, 2, np.nan], "B": list("abc"), "C": [4, np.nan, 5]}) expected = DataFrame({"A": [1.0], "B": ["a"], "C": [4.0]}) result = df.dropna(subset=np.array(["A", "C"])) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_dtypes.py b/pandas/tests/frame/methods/test_dtypes.py index 6f21bd4c4b438..4bdf16977dae6 100644 --- a/pandas/tests/frame/methods/test_dtypes.py +++ b/pandas/tests/frame/methods/test_dtypes.py @@ -62,15 +62,15 @@ def test_datetime_with_tz_dtypes(self): def test_dtypes_are_correct_after_column_slice(self): # GH6525 - df = DataFrame(index=range(5), columns=list("abc"), dtype=np.float_) + df = DataFrame(index=range(5), columns=list("abc"), dtype=np.float64) tm.assert_series_equal( df.dtypes, - Series({"a": np.float_, "b": np.float_, "c": np.float_}), + Series({"a": np.float64, "b": np.float64, "c": np.float64}), ) - tm.assert_series_equal(df.iloc[:, 2:].dtypes, Series({"c": np.float_})) + tm.assert_series_equal(df.iloc[:, 2:].dtypes, Series({"c": np.float64})) tm.assert_series_equal( df.dtypes, - Series({"a": np.float_, "b": np.float_, "c": np.float_}), + Series({"a": np.float64, "b": np.float64, "c": np.float64}), ) @pytest.mark.parametrize( diff --git a/pandas/tests/frame/methods/test_replace.py b/pandas/tests/frame/methods/test_replace.py index 3203482ddf724..61e44b4e24c08 100644 --- a/pandas/tests/frame/methods/test_replace.py +++ b/pandas/tests/frame/methods/test_replace.py @@ -666,7 +666,7 @@ def test_replace_NA_with_None(self): def test_replace_NAT_with_None(self): # gh-45836 df = DataFrame([pd.NaT, pd.NaT]) - result = df.replace({pd.NaT: None, np.NaN: None}) + result = df.replace({pd.NaT: None, np.nan: None}) expected = DataFrame([None, None]) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_select_dtypes.py b/pandas/tests/frame/methods/test_select_dtypes.py index 3bfb1af423bdd..67dd5b6217187 100644 --- a/pandas/tests/frame/methods/test_select_dtypes.py +++ b/pandas/tests/frame/methods/test_select_dtypes.py @@ -340,7 +340,7 @@ def test_select_dtypes_datetime_with_tz(self): tm.assert_frame_equal(result, expected) @pytest.mark.parametrize( - "dtype", [str, "str", np.string_, "S1", "unicode", np.unicode_, "U1"] + "dtype", [str, "str", np.bytes_, "S1", "unicode", np.str_, "U1"] ) @pytest.mark.parametrize("arg", ["include", "exclude"]) def test_select_dtypes_str_raises(self, dtype, arg): diff --git a/pandas/tests/frame/methods/test_shift.py b/pandas/tests/frame/methods/test_shift.py index 35941e9f24a4e..808f0cff2485c 100644 --- a/pandas/tests/frame/methods/test_shift.py +++ b/pandas/tests/frame/methods/test_shift.py @@ -681,10 +681,10 @@ def test_shift_with_iterable_basic_functionality(self): { "a_0": [1, 2, 3], "b_0": [4, 5, 6], - "a_1": [np.NaN, 1.0, 2.0], - "b_1": [np.NaN, 4.0, 5.0], - "a_2": [np.NaN, np.NaN, 1.0], - "b_2": [np.NaN, np.NaN, 4.0], + "a_1": [np.nan, 1.0, 2.0], + "b_1": [np.nan, 4.0, 5.0], + "a_2": [np.nan, np.nan, 1.0], + "b_2": [np.nan, np.nan, 4.0], } ) tm.assert_frame_equal(expected, shifted) diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index 008d7a023576a..9e8d92e832d01 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -131,22 +131,22 @@ def test_constructor_with_convert(self): df = DataFrame({"A": [None, 1]}) result = df["A"] - expected = Series(np.asarray([np.nan, 1], np.float_), name="A") + expected = Series(np.asarray([np.nan, 1], np.float64), name="A") tm.assert_series_equal(result, expected) df = DataFrame({"A": [1.0, 2]}) result = df["A"] - expected = Series(np.asarray([1.0, 2], np.float_), name="A") + expected = Series(np.asarray([1.0, 2], np.float64), name="A") tm.assert_series_equal(result, expected) df = DataFrame({"A": [1.0 + 2.0j, 3]}) result = df["A"] - expected = Series(np.asarray([1.0 + 2.0j, 3], np.complex_), name="A") + expected = Series(np.asarray([1.0 + 2.0j, 3], np.complex128), name="A") tm.assert_series_equal(result, expected) df = DataFrame({"A": [1.0 + 2.0j, 3.0]}) result = df["A"] - expected = Series(np.asarray([1.0 + 2.0j, 3.0], np.complex_), name="A") + expected = Series(np.asarray([1.0 + 2.0j, 3.0], np.complex128), name="A") tm.assert_series_equal(result, expected) df = DataFrame({"A": [1.0 + 2.0j, True]}) @@ -156,12 +156,12 @@ def test_constructor_with_convert(self): df = DataFrame({"A": [1.0, None]}) result = df["A"] - expected = Series(np.asarray([1.0, np.nan], np.float_), name="A") + expected = Series(np.asarray([1.0, np.nan], np.float64), name="A") tm.assert_series_equal(result, expected) df = DataFrame({"A": [1.0 + 2.0j, None]}) result = df["A"] - expected = Series(np.asarray([1.0 + 2.0j, np.nan], np.complex_), name="A") + expected = Series(np.asarray([1.0 + 2.0j, np.nan], np.complex128), name="A") tm.assert_series_equal(result, expected) df = DataFrame({"A": [2.0, 1, True, None]}) @@ -343,9 +343,9 @@ def test_stale_cached_series_bug_473(self, using_copy_on_write): Y["e"] = Y["e"].astype("object") if using_copy_on_write: with tm.raises_chained_assignment_error(): - Y["g"]["c"] = np.NaN + Y["g"]["c"] = np.nan else: - Y["g"]["c"] = np.NaN + Y["g"]["c"] = np.nan repr(Y) Y.sum() Y["g"].sum() diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index a493084142f7b..c170704150383 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -1781,8 +1781,6 @@ def test_constructor_empty_with_string_dtype(self): tm.assert_frame_equal(df, expected) df = DataFrame(index=[0, 1], columns=[0, 1], dtype=np.str_) tm.assert_frame_equal(df, expected) - df = DataFrame(index=[0, 1], columns=[0, 1], dtype=np.unicode_) - tm.assert_frame_equal(df, expected) df = DataFrame(index=[0, 1], columns=[0, 1], dtype="U5") tm.assert_frame_equal(df, expected) @@ -1826,7 +1824,7 @@ def test_constructor_single_value(self): def test_constructor_with_datetimes(self): intname = np.dtype(np.int_).name - floatname = np.dtype(np.float_).name + floatname = np.dtype(np.float64).name objectname = np.dtype(np.object_).name # single item diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index ab36934533beb..e7b6a0c0b39b0 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -134,7 +134,7 @@ def wrapper(x): # all NA case if has_skipna: - all_na = frame * np.NaN + all_na = frame * np.nan r0 = getattr(all_na, opname)(axis=0) r1 = getattr(all_na, opname)(axis=1) if opname in ["sum", "prod"]: @@ -834,9 +834,9 @@ def test_sum_nanops_min_count(self): @pytest.mark.parametrize( "kwargs, expected_result", [ - ({"axis": 1, "min_count": 2}, [3.2, 5.3, np.NaN]), - ({"axis": 1, "min_count": 3}, [np.NaN, np.NaN, np.NaN]), - ({"axis": 1, "skipna": False}, [3.2, 5.3, np.NaN]), + ({"axis": 1, "min_count": 2}, [3.2, 5.3, np.nan]), + ({"axis": 1, "min_count": 3}, [np.nan, np.nan, np.nan]), + ({"axis": 1, "skipna": False}, [3.2, 5.3, np.nan]), ], ) def test_sum_nanops_dtype_min_count(self, float_type, kwargs, expected_result): @@ -850,9 +850,9 @@ def test_sum_nanops_dtype_min_count(self, float_type, kwargs, expected_result): @pytest.mark.parametrize( "kwargs, expected_result", [ - ({"axis": 1, "min_count": 2}, [2.0, 4.0, np.NaN]), - ({"axis": 1, "min_count": 3}, [np.NaN, np.NaN, np.NaN]), - ({"axis": 1, "skipna": False}, [2.0, 4.0, np.NaN]), + ({"axis": 1, "min_count": 2}, [2.0, 4.0, np.nan]), + ({"axis": 1, "min_count": 3}, [np.nan, np.nan, np.nan]), + ({"axis": 1, "skipna": False}, [2.0, 4.0, np.nan]), ], ) def test_prod_nanops_dtype_min_count(self, float_type, kwargs, expected_result): @@ -1189,7 +1189,7 @@ def wrapper(x): f(axis=2) # all NA case - all_na = frame * np.NaN + all_na = frame * np.nan r0 = getattr(all_na, opname)(axis=0) r1 = getattr(all_na, opname)(axis=1) if opname == "any": diff --git a/pandas/tests/frame/test_stack_unstack.py b/pandas/tests/frame/test_stack_unstack.py index cb8e8c5025e3b..c90b871d5d66f 100644 --- a/pandas/tests/frame/test_stack_unstack.py +++ b/pandas/tests/frame/test_stack_unstack.py @@ -72,7 +72,7 @@ def test_stack_mixed_level(self, future_stack): def test_unstack_not_consolidated(self, using_array_manager): # Gh#34708 - df = DataFrame({"x": [1, 2, np.NaN], "y": [3.0, 4, np.NaN]}) + df = DataFrame({"x": [1, 2, np.nan], "y": [3.0, 4, np.nan]}) df2 = df[["x"]] df2["y"] = df["y"] if not using_array_manager: @@ -584,7 +584,7 @@ def test_unstack_to_series(self, float_frame): tm.assert_frame_equal(undo, float_frame) # check NA handling - data = DataFrame({"x": [1, 2, np.NaN], "y": [3.0, 4, np.NaN]}) + data = DataFrame({"x": [1, 2, np.nan], "y": [3.0, 4, np.nan]}) data.index = Index(["a", "b", "c"]) result = data.unstack() @@ -592,7 +592,7 @@ def test_unstack_to_series(self, float_frame): levels=[["x", "y"], ["a", "b", "c"]], codes=[[0, 0, 0, 1, 1, 1], [0, 1, 2, 0, 1, 2]], ) - expected = Series([1, 2, np.NaN, 3, 4, np.NaN], index=midx) + expected = Series([1, 2, np.nan, 3, 4, np.nan], index=midx) tm.assert_series_equal(result, expected) @@ -902,9 +902,9 @@ def cast(val): def test_unstack_nan_index2(self): # GH7403 df = DataFrame({"A": list("aaaabbbb"), "B": range(8), "C": range(8)}) - # Explicit cast to avoid implicit cast when setting to np.NaN + # Explicit cast to avoid implicit cast when setting to np.nan df = df.astype({"B": "float"}) - df.iloc[3, 1] = np.NaN + df.iloc[3, 1] = np.nan left = df.set_index(["A", "B"]).unstack(0) vals = [ @@ -921,9 +921,9 @@ def test_unstack_nan_index2(self): tm.assert_frame_equal(left, right) df = DataFrame({"A": list("aaaabbbb"), "B": list(range(4)) * 2, "C": range(8)}) - # Explicit cast to avoid implicit cast when setting to np.NaN + # Explicit cast to avoid implicit cast when setting to np.nan df = df.astype({"B": "float"}) - df.iloc[2, 1] = np.NaN + df.iloc[2, 1] = np.nan left = df.set_index(["A", "B"]).unstack(0) vals = [[2, np.nan], [0, 4], [1, 5], [np.nan, 6], [3, 7]] @@ -935,9 +935,9 @@ def test_unstack_nan_index2(self): tm.assert_frame_equal(left, right) df = DataFrame({"A": list("aaaabbbb"), "B": list(range(4)) * 2, "C": range(8)}) - # Explicit cast to avoid implicit cast when setting to np.NaN + # Explicit cast to avoid implicit cast when setting to np.nan df = df.astype({"B": "float"}) - df.iloc[3, 1] = np.NaN + df.iloc[3, 1] = np.nan left = df.set_index(["A", "B"]).unstack(0) vals = [[3, np.nan], [0, 4], [1, 5], [2, 6], [np.nan, 7]] @@ -958,7 +958,7 @@ def test_unstack_nan_index3(self, using_array_manager): } ) - df.iloc[3, 1] = np.NaN + df.iloc[3, 1] = np.nan left = df.set_index(["A", "B"]).unstack() vals = np.array([[3, 0, 1, 2, np.nan, 4], [np.nan, 5, 6, 7, 8, 9]]) @@ -1754,7 +1754,7 @@ def test_stack_mixed_dtype(self, multiindex_dataframe_random_data, future_stack) result = df["foo"].stack(future_stack=future_stack).sort_index() tm.assert_series_equal(stacked["foo"], result, check_names=False) assert result.name is None - assert stacked["bar"].dtype == np.float_ + assert stacked["bar"].dtype == np.float64 def test_unstack_bug(self, future_stack): df = DataFrame( diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index d0ae9eeed394f..68ce58ad23690 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -18,7 +18,7 @@ from pandas.tests.groupby import get_groupby_method_args -def cartesian_product_for_groupers(result, args, names, fill_value=np.NaN): +def cartesian_product_for_groupers(result, args, names, fill_value=np.nan): """Reindex to a cartesian production for the groupers, preserving the nature (Categorical) of each grouper """ @@ -42,28 +42,28 @@ def f(a): # These expected values can be used across several tests (i.e. they are # the same for SeriesGroupBy and DataFrameGroupBy) but they should only be # hardcoded in one place. - "all": np.NaN, - "any": np.NaN, + "all": np.nan, + "any": np.nan, "count": 0, - "corrwith": np.NaN, - "first": np.NaN, - "idxmax": np.NaN, - "idxmin": np.NaN, - "last": np.NaN, - "max": np.NaN, - "mean": np.NaN, - "median": np.NaN, - "min": np.NaN, - "nth": np.NaN, + "corrwith": np.nan, + "first": np.nan, + "idxmax": np.nan, + "idxmin": np.nan, + "last": np.nan, + "max": np.nan, + "mean": np.nan, + "median": np.nan, + "min": np.nan, + "nth": np.nan, "nunique": 0, - "prod": np.NaN, - "quantile": np.NaN, - "sem": np.NaN, + "prod": np.nan, + "quantile": np.nan, + "sem": np.nan, "size": 0, - "skew": np.NaN, - "std": np.NaN, + "skew": np.nan, + "std": np.nan, "sum": 0, - "var": np.NaN, + "var": np.nan, } @@ -1750,8 +1750,8 @@ def test_series_groupby_first_on_categorical_col_grouped_on_2_categoricals( cat2 = Categorical([0, 1]) idx = MultiIndex.from_product([cat2, cat2], names=["a", "b"]) expected_dict = { - "first": Series([0, np.NaN, np.NaN, 1], idx, name="c"), - "last": Series([1, np.NaN, np.NaN, 0], idx, name="c"), + "first": Series([0, np.nan, np.nan, 1], idx, name="c"), + "last": Series([1, np.nan, np.nan, 0], idx, name="c"), } expected = expected_dict[func] @@ -1775,8 +1775,8 @@ def test_df_groupby_first_on_categorical_col_grouped_on_2_categoricals( cat2 = Categorical([0, 1]) idx = MultiIndex.from_product([cat2, cat2], names=["a", "b"]) expected_dict = { - "first": Series([0, np.NaN, np.NaN, 1], idx, name="c"), - "last": Series([1, np.NaN, np.NaN, 0], idx, name="c"), + "first": Series([0, np.nan, np.nan, 1], idx, name="c"), + "last": Series([1, np.nan, np.nan, 0], idx, name="c"), } expected = expected_dict[func].to_frame() diff --git a/pandas/tests/groupby/test_counting.py b/pandas/tests/groupby/test_counting.py index fd5018d05380c..6c27344ce3110 100644 --- a/pandas/tests/groupby/test_counting.py +++ b/pandas/tests/groupby/test_counting.py @@ -232,7 +232,7 @@ def test_count_with_only_nans_in_first_group(self): def test_count_groupby_column_with_nan_in_groupby_column(self): # https://github.com/pandas-dev/pandas/issues/32841 - df = DataFrame({"A": [1, 1, 1, 1, 1], "B": [5, 4, np.NaN, 3, 0]}) + df = DataFrame({"A": [1, 1, 1, 1, 1], "B": [5, 4, np.nan, 3, 0]}) res = df.groupby(["B"]).count() expected = DataFrame( index=Index([0.0, 3.0, 4.0, 5.0], name="B"), data={"A": [1, 1, 1, 1]} diff --git a/pandas/tests/groupby/test_rank.py b/pandas/tests/groupby/test_rank.py index 26881bdd18274..5d85a0783e024 100644 --- a/pandas/tests/groupby/test_rank.py +++ b/pandas/tests/groupby/test_rank.py @@ -578,7 +578,7 @@ def test_rank_min_int(): result = df.groupby("grp").rank() expected = DataFrame( - {"int_col": [1.0, 2.0, 1.0], "datetimelike": [np.NaN, 1.0, np.NaN]} + {"int_col": [1.0, 2.0, 1.0], "datetimelike": [np.nan, 1.0, np.nan]} ) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/indexes/datetimes/methods/test_astype.py b/pandas/tests/indexes/datetimes/methods/test_astype.py index 94cf86b7fb9c5..d339639dc5def 100644 --- a/pandas/tests/indexes/datetimes/methods/test_astype.py +++ b/pandas/tests/indexes/datetimes/methods/test_astype.py @@ -20,7 +20,7 @@ class TestDatetimeIndex: def test_astype(self): # GH 13149, GH 13209 - idx = DatetimeIndex(["2016-05-16", "NaT", NaT, np.NaN], name="idx") + idx = DatetimeIndex(["2016-05-16", "NaT", NaT, np.nan], name="idx") result = idx.astype(object) expected = Index( @@ -84,7 +84,7 @@ def test_astype_str_nat(self): # GH 13149, GH 13209 # verify that we are returning NaT as a string (and not unicode) - idx = DatetimeIndex(["2016-05-16", "NaT", NaT, np.NaN]) + idx = DatetimeIndex(["2016-05-16", "NaT", NaT, np.nan]) result = idx.astype(str) expected = Index(["2016-05-16", "NaT", "NaT", "NaT"], dtype=object) tm.assert_index_equal(result, expected) @@ -141,7 +141,7 @@ def test_astype_str_freq_and_tz(self): def test_astype_datetime64(self): # GH 13149, GH 13209 - idx = DatetimeIndex(["2016-05-16", "NaT", NaT, np.NaN], name="idx") + idx = DatetimeIndex(["2016-05-16", "NaT", NaT, np.nan], name="idx") result = idx.astype("datetime64[ns]") tm.assert_index_equal(result, idx) @@ -151,7 +151,7 @@ def test_astype_datetime64(self): tm.assert_index_equal(result, idx) assert result is idx - idx_tz = DatetimeIndex(["2016-05-16", "NaT", NaT, np.NaN], tz="EST", name="idx") + idx_tz = DatetimeIndex(["2016-05-16", "NaT", NaT, np.nan], tz="EST", name="idx") msg = "Cannot use .astype to convert from timezone-aware" with pytest.raises(TypeError, match=msg): # dt64tz->dt64 deprecated @@ -202,7 +202,7 @@ def test_astype_object_with_nat(self): ) def test_astype_raises(self, dtype): # GH 13149, GH 13209 - idx = DatetimeIndex(["2016-05-16", "NaT", NaT, np.NaN]) + idx = DatetimeIndex(["2016-05-16", "NaT", NaT, np.nan]) msg = "Cannot cast DatetimeIndex to dtype" if dtype == "datetime64": msg = "Casting to unit-less dtype 'datetime64' is not supported" diff --git a/pandas/tests/indexes/datetimes/test_timezones.py b/pandas/tests/indexes/datetimes/test_timezones.py index 6f3c83b999e94..09b06ecd5630d 100644 --- a/pandas/tests/indexes/datetimes/test_timezones.py +++ b/pandas/tests/indexes/datetimes/test_timezones.py @@ -538,8 +538,8 @@ def test_dti_tz_localize_ambiguous_nat(self, tz): times = [ "11/06/2011 00:00", - np.NaN, - np.NaN, + np.nan, + np.nan, "11/06/2011 02:00", "11/06/2011 03:00", ] diff --git a/pandas/tests/indexes/interval/test_interval.py b/pandas/tests/indexes/interval/test_interval.py index 49e8df2b71f22..aff4944e7bd55 100644 --- a/pandas/tests/indexes/interval/test_interval.py +++ b/pandas/tests/indexes/interval/test_interval.py @@ -247,12 +247,12 @@ def test_is_unique_interval(self, closed): assert idx.is_unique is True # unique NaN - idx = IntervalIndex.from_tuples([(np.NaN, np.NaN)], closed=closed) + idx = IntervalIndex.from_tuples([(np.nan, np.nan)], closed=closed) assert idx.is_unique is True # non-unique NaN idx = IntervalIndex.from_tuples( - [(np.NaN, np.NaN), (np.NaN, np.NaN)], closed=closed + [(np.nan, np.nan), (np.nan, np.nan)], closed=closed ) assert idx.is_unique is False diff --git a/pandas/tests/indexes/multi/test_join.py b/pandas/tests/indexes/multi/test_join.py index c5a3512113655..700af142958b3 100644 --- a/pandas/tests/indexes/multi/test_join.py +++ b/pandas/tests/indexes/multi/test_join.py @@ -217,7 +217,7 @@ def test_join_multi_with_nan(): ) df2 = DataFrame( data={"col2": [2.1, 2.2]}, - index=MultiIndex.from_product([["A"], [np.NaN, 2.0]], names=["id1", "id2"]), + index=MultiIndex.from_product([["A"], [np.nan, 2.0]], names=["id1", "id2"]), ) result = df1.join(df2) expected = DataFrame( diff --git a/pandas/tests/indexes/period/methods/test_astype.py b/pandas/tests/indexes/period/methods/test_astype.py index 2a605d136175e..e54cd73a35f59 100644 --- a/pandas/tests/indexes/period/methods/test_astype.py +++ b/pandas/tests/indexes/period/methods/test_astype.py @@ -17,14 +17,14 @@ class TestPeriodIndexAsType: @pytest.mark.parametrize("dtype", [float, "timedelta64", "timedelta64[ns]"]) def test_astype_raises(self, dtype): # GH#13149, GH#13209 - idx = PeriodIndex(["2016-05-16", "NaT", NaT, np.NaN], freq="D") + idx = PeriodIndex(["2016-05-16", "NaT", NaT, np.nan], freq="D") msg = "Cannot cast PeriodIndex to dtype" with pytest.raises(TypeError, match=msg): idx.astype(dtype) def test_astype_conversion(self): # GH#13149, GH#13209 - idx = PeriodIndex(["2016-05-16", "NaT", NaT, np.NaN], freq="D", name="idx") + idx = PeriodIndex(["2016-05-16", "NaT", NaT, np.nan], freq="D", name="idx") result = idx.astype(object) expected = Index( diff --git a/pandas/tests/indexes/period/test_pickle.py b/pandas/tests/indexes/period/test_pickle.py index 82f906d1e361f..cb981ab10064f 100644 --- a/pandas/tests/indexes/period/test_pickle.py +++ b/pandas/tests/indexes/period/test_pickle.py @@ -14,7 +14,7 @@ class TestPickle: @pytest.mark.parametrize("freq", ["D", "M", "A"]) def test_pickle_round_trip(self, freq): - idx = PeriodIndex(["2016-05-16", "NaT", NaT, np.NaN], freq=freq) + idx = PeriodIndex(["2016-05-16", "NaT", NaT, np.nan], freq=freq) result = tm.round_trip_pickle(idx) tm.assert_index_equal(result, idx) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index b3fb5a26ca63f..ffa0b115e34fb 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -473,7 +473,7 @@ def test_empty_fancy(self, index, dtype): def test_empty_fancy_raises(self, index): # DatetimeIndex is excluded, because it overrides getitem and should # be tested separately. - empty_farr = np.array([], dtype=np.float_) + empty_farr = np.array([], dtype=np.float64) empty_index = type(index)([], dtype=index.dtype) assert index[[]].identical(empty_index) diff --git a/pandas/tests/indexes/timedeltas/methods/test_astype.py b/pandas/tests/indexes/timedeltas/methods/test_astype.py index 9b17a8af59ac5..f69f0fd3d78e2 100644 --- a/pandas/tests/indexes/timedeltas/methods/test_astype.py +++ b/pandas/tests/indexes/timedeltas/methods/test_astype.py @@ -45,7 +45,7 @@ def test_astype_object_with_nat(self): def test_astype(self): # GH 13149, GH 13209 - idx = TimedeltaIndex([1e14, "NaT", NaT, np.NaN], name="idx") + idx = TimedeltaIndex([1e14, "NaT", NaT, np.nan], name="idx") result = idx.astype(object) expected = Index( @@ -78,7 +78,7 @@ def test_astype_uint(self): def test_astype_timedelta64(self): # GH 13149, GH 13209 - idx = TimedeltaIndex([1e14, "NaT", NaT, np.NaN]) + idx = TimedeltaIndex([1e14, "NaT", NaT, np.nan]) msg = ( r"Cannot convert from timedelta64\[ns\] to timedelta64. " @@ -98,7 +98,7 @@ def test_astype_timedelta64(self): @pytest.mark.parametrize("dtype", [float, "datetime64", "datetime64[ns]"]) def test_astype_raises(self, dtype): # GH 13149, GH 13209 - idx = TimedeltaIndex([1e14, "NaT", NaT, np.NaN]) + idx = TimedeltaIndex([1e14, "NaT", NaT, np.nan]) msg = "Cannot cast TimedeltaIndex to dtype" with pytest.raises(TypeError, match=msg): idx.astype(dtype) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index abbf22a7fc70a..d0b6adfda0241 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -201,7 +201,7 @@ def test_column_types_consistent(self): df = DataFrame( data={ "channel": [1, 2, 3], - "A": ["String 1", np.NaN, "String 2"], + "A": ["String 1", np.nan, "String 2"], "B": [ Timestamp("2019-06-11 11:00:00"), pd.NaT, diff --git a/pandas/tests/interchange/test_impl.py b/pandas/tests/interchange/test_impl.py index 2a65937a82200..8a25a2c1889f3 100644 --- a/pandas/tests/interchange/test_impl.py +++ b/pandas/tests/interchange/test_impl.py @@ -32,7 +32,7 @@ def string_data(): "234,3245.67", "gSaf,qWer|Gre", "asd3,4sad|", - np.NaN, + np.nan, ] } diff --git a/pandas/tests/internals/test_internals.py b/pandas/tests/internals/test_internals.py index 97d9f13bd9e9e..b7108896f01ed 100644 --- a/pandas/tests/internals/test_internals.py +++ b/pandas/tests/internals/test_internals.py @@ -473,7 +473,7 @@ def test_set_change_dtype(self, mgr): mgr2.iset( mgr2.items.get_loc("quux"), np.random.default_rng(2).standard_normal(N) ) - assert mgr2.iget(idx).dtype == np.float_ + assert mgr2.iget(idx).dtype == np.float64 def test_copy(self, mgr): cp = mgr.copy(deep=False) diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 32509a799fa69..c8e984a92f418 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -181,7 +181,7 @@ def test_to_csv_na_rep(self): # see gh-11553 # # Testing if NaN values are correctly represented in the index. - df = DataFrame({"a": [0, np.NaN], "b": [0, 1], "c": [2, 3]}) + df = DataFrame({"a": [0, np.nan], "b": [0, 1], "c": [2, 3]}) expected_rows = ["a,b,c", "0.0,0,2", "_,1,3"] expected = tm.convert_rows_list_to_csv_str(expected_rows) @@ -189,7 +189,7 @@ def test_to_csv_na_rep(self): assert df.set_index(["a", "b"]).to_csv(na_rep="_") == expected # now with an index containing only NaNs - df = DataFrame({"a": np.NaN, "b": [0, 1], "c": [2, 3]}) + df = DataFrame({"a": np.nan, "b": [0, 1], "c": [2, 3]}) expected_rows = ["a,b,c", "_,0,2", "_,1,3"] expected = tm.convert_rows_list_to_csv_str(expected_rows) diff --git a/pandas/tests/io/parser/test_parse_dates.py b/pandas/tests/io/parser/test_parse_dates.py index eecacf29de872..c79fdd9145a6a 100644 --- a/pandas/tests/io/parser/test_parse_dates.py +++ b/pandas/tests/io/parser/test_parse_dates.py @@ -46,7 +46,7 @@ def test_read_csv_with_custom_date_parser(all_parsers): # GH36111 def __custom_date_parser(time): - time = time.astype(np.float_) + time = time.astype(np.float64) time = time.astype(np.int_) # convert float seconds to int type return pd.to_timedelta(time, unit="s") @@ -86,7 +86,7 @@ def __custom_date_parser(time): def test_read_csv_with_custom_date_parser_parse_dates_false(all_parsers): # GH44366 def __custom_date_parser(time): - time = time.astype(np.float_) + time = time.astype(np.float64) time = time.astype(np.int_) # convert float seconds to int type return pd.to_timedelta(time, unit="s") diff --git a/pandas/tests/io/test_stata.py b/pandas/tests/io/test_stata.py index 3cfd86049588b..7459aa1df8f3e 100644 --- a/pandas/tests/io/test_stata.py +++ b/pandas/tests/io/test_stata.py @@ -1475,9 +1475,9 @@ def test_stata_111(self, datapath): df = read_stata(datapath("io", "data", "stata", "stata7_111.dta")) original = DataFrame( { - "y": [1, 1, 1, 1, 1, 0, 0, np.NaN, 0, 0], - "x": [1, 2, 1, 3, np.NaN, 4, 3, 5, 1, 6], - "w": [2, np.NaN, 5, 2, 4, 4, 3, 1, 2, 3], + "y": [1, 1, 1, 1, 1, 0, 0, np.nan, 0, 0], + "x": [1, 2, 1, 3, np.nan, 4, 3, 5, 1, 6], + "w": [2, np.nan, 5, 2, 4, 4, 3, 1, 2, 3], "z": ["a", "b", "c", "d", "e", "", "g", "h", "i", "j"], } ) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index afe5b3c66a611..87892a81cef3d 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -867,7 +867,7 @@ def test_idxmin(self): string_series = tm.makeStringSeries().rename("series") # add some NaNs - string_series[5:15] = np.NaN + string_series[5:15] = np.nan # skipna or no assert string_series[string_series.idxmin()] == string_series.min() @@ -900,7 +900,7 @@ def test_idxmax(self): string_series = tm.makeStringSeries().rename("series") # add some NaNs - string_series[5:15] = np.NaN + string_series[5:15] = np.nan # skipna or no assert string_series[string_series.idxmax()] == string_series.max() diff --git a/pandas/tests/reductions/test_stat_reductions.py b/pandas/tests/reductions/test_stat_reductions.py index 58c5fc7269aee..55d78c516b6f3 100644 --- a/pandas/tests/reductions/test_stat_reductions.py +++ b/pandas/tests/reductions/test_stat_reductions.py @@ -99,7 +99,7 @@ def _check_stat_op( f = getattr(Series, name) # add some NaNs - string_series_[5:15] = np.NaN + string_series_[5:15] = np.nan # mean, idxmax, idxmin, min, and max are valid for dates if name not in ["max", "min", "mean", "median", "std"]: diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 1d72e6d3970ca..dbda751e82113 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -478,7 +478,7 @@ def test_resample_how_method(unit): ) s.index = s.index.as_unit(unit) expected = Series( - [11, np.NaN, np.NaN, np.NaN, np.NaN, np.NaN, 22], + [11, np.nan, np.nan, np.nan, np.nan, np.nan, 22], index=DatetimeIndex( [ Timestamp("2015-03-31 21:48:50"), @@ -1356,7 +1356,7 @@ def test_resample_consistency(unit): i30 = date_range("2002-02-02", periods=4, freq="30T").as_unit(unit) s = Series(np.arange(4.0), index=i30) - s.iloc[2] = np.NaN + s.iloc[2] = np.nan # Upsample by factor 3 with reindex() and resample() methods: i10 = date_range(i30[0], i30[-1], freq="10T").as_unit(unit) diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index 0ded7d7e6bfc5..7559a85de7a6b 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -793,7 +793,7 @@ def test_upsampling_ohlc(self, freq, period_mult, kind): @pytest.mark.parametrize( "freq, expected_values", [ - ("1s", [3, np.NaN, 7, 11]), + ("1s", [3, np.nan, 7, 11]), ("2s", [3, (7 + 11) / 2]), ("3s", [(3 + 7) / 2, 11]), ], diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index 869bf3ace9492..3efcd930af581 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -507,10 +507,10 @@ def test_concat_duplicate_indices_raise(self): concat([df1, df2], axis=1) -@pytest.mark.parametrize("dt", np.sctypes["float"]) -def test_concat_no_unnecessary_upcast(dt, frame_or_series): +def test_concat_no_unnecessary_upcast(float_numpy_dtype, frame_or_series): # GH 13247 dims = frame_or_series(dtype=object).ndim + dt = float_numpy_dtype dfs = [ frame_or_series(np.array([1], dtype=dt, ndmin=dims)), @@ -522,8 +522,8 @@ def test_concat_no_unnecessary_upcast(dt, frame_or_series): @pytest.mark.parametrize("pdt", [Series, DataFrame]) -@pytest.mark.parametrize("dt", np.sctypes["int"]) -def test_concat_will_upcast(dt, pdt): +def test_concat_will_upcast(pdt, any_signed_int_numpy_dtype): + dt = any_signed_int_numpy_dtype dims = pdt().ndim dfs = [ pdt(np.array([1], dtype=dt, ndmin=dims)), diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 43786ee15d138..46da18445e135 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -1950,7 +1950,7 @@ def test_pivot_table_not_series(self): result = df.pivot_table("col1", index="col3", columns="col2", aggfunc="sum") expected = DataFrame( - [[3, np.NaN, np.NaN], [np.NaN, 4, np.NaN], [np.NaN, np.NaN, 5]], + [[3, np.nan, np.nan], [np.nan, 4, np.nan], [np.nan, np.nan, 5]], index=Index([1, 3, 9], name="col3"), columns=Index(["C", "D", "E"], name="col2"), ) @@ -2424,7 +2424,7 @@ def test_pivot_table_aggfunc_nunique_with_different_values(self): ], names=(None, None, "b"), ) - nparr = np.full((10, 10), np.NaN) + nparr = np.full((10, 10), np.nan) np.fill_diagonal(nparr, 1.0) expected = DataFrame(nparr, index=Index(range(10), name="a"), columns=columnval) diff --git a/pandas/tests/scalar/test_na_scalar.py b/pandas/tests/scalar/test_na_scalar.py index 213fa1791838d..287b7557f50f9 100644 --- a/pandas/tests/scalar/test_na_scalar.py +++ b/pandas/tests/scalar/test_na_scalar.py @@ -103,9 +103,9 @@ def test_comparison_ops(comparison_op, other): False, np.bool_(False), np.int_(0), - np.float_(0), + np.float64(0), np.int_(-0), - np.float_(-0), + np.float64(-0), ], ) @pytest.mark.parametrize("asarray", [True, False]) @@ -123,7 +123,7 @@ def test_pow_special(value, asarray): @pytest.mark.parametrize( - "value", [1, 1.0, True, np.bool_(True), np.int_(1), np.float_(1)] + "value", [1, 1.0, True, np.bool_(True), np.int_(1), np.float64(1)] ) @pytest.mark.parametrize("asarray", [True, False]) def test_rpow_special(value, asarray): @@ -133,14 +133,14 @@ def test_rpow_special(value, asarray): if asarray: result = result[0] - elif not isinstance(value, (np.float_, np.bool_, np.int_)): + elif not isinstance(value, (np.float64, np.bool_, np.int_)): # this assertion isn't possible with asarray=True assert isinstance(result, type(value)) assert result == value -@pytest.mark.parametrize("value", [-1, -1.0, np.int_(-1), np.float_(-1)]) +@pytest.mark.parametrize("value", [-1, -1.0, np.int_(-1), np.float64(-1)]) @pytest.mark.parametrize("asarray", [True, False]) def test_rpow_minus_one(value, asarray): if asarray: diff --git a/pandas/tests/series/accessors/test_dt_accessor.py b/pandas/tests/series/accessors/test_dt_accessor.py index e7fea9aa597b8..dd810a31c25af 100644 --- a/pandas/tests/series/accessors/test_dt_accessor.py +++ b/pandas/tests/series/accessors/test_dt_accessor.py @@ -739,9 +739,9 @@ def test_dt_timetz_accessor(self, tz_naive_fixture): "input_series, expected_output", [ [["2020-01-01"], [[2020, 1, 3]]], - [[pd.NaT], [[np.NaN, np.NaN, np.NaN]]], + [[pd.NaT], [[np.nan, np.nan, np.nan]]], [["2019-12-31", "2019-12-29"], [[2020, 1, 2], [2019, 52, 7]]], - [["2010-01-01", pd.NaT], [[2009, 53, 5], [np.NaN, np.NaN, np.NaN]]], + [["2010-01-01", pd.NaT], [[2009, 53, 5], [np.nan, np.nan, np.nan]]], # see GH#36032 [["2016-01-08", "2016-01-04"], [[2016, 1, 5], [2016, 1, 1]]], [["2016-01-07", "2016-01-01"], [[2016, 1, 4], [2015, 53, 5]]], diff --git a/pandas/tests/series/indexing/test_indexing.py b/pandas/tests/series/indexing/test_indexing.py index 20f8dd1fc5b2a..7b857a487db78 100644 --- a/pandas/tests/series/indexing/test_indexing.py +++ b/pandas/tests/series/indexing/test_indexing.py @@ -196,9 +196,9 @@ def test_setitem_ambiguous_keyerror(indexer_sl): def test_setitem(datetime_series): - datetime_series[datetime_series.index[5]] = np.NaN - datetime_series.iloc[[1, 2, 17]] = np.NaN - datetime_series.iloc[6] = np.NaN + datetime_series[datetime_series.index[5]] = np.nan + datetime_series.iloc[[1, 2, 17]] = np.nan + datetime_series.iloc[6] = np.nan assert np.isnan(datetime_series.iloc[6]) assert np.isnan(datetime_series.iloc[2]) datetime_series[np.isnan(datetime_series)] = 5 @@ -304,7 +304,7 @@ def test_underlying_data_conversion(using_copy_on_write): def test_preserve_refs(datetime_series): seq = datetime_series.iloc[[5, 10, 15]] - seq.iloc[1] = np.NaN + seq.iloc[1] = np.nan assert not np.isnan(datetime_series.iloc[10]) diff --git a/pandas/tests/series/methods/test_argsort.py b/pandas/tests/series/methods/test_argsort.py index bd8b7b34bd402..5bcf42aad1db4 100644 --- a/pandas/tests/series/methods/test_argsort.py +++ b/pandas/tests/series/methods/test_argsort.py @@ -27,7 +27,7 @@ def test_argsort_numpy(self, datetime_series): # with missing values ts = ser.copy() - ts[::2] = np.NaN + ts[::2] = np.nan msg = "The behavior of Series.argsort in the presence of NA values" with tm.assert_produces_warning( diff --git a/pandas/tests/series/methods/test_asof.py b/pandas/tests/series/methods/test_asof.py index d5f99f721d323..31c264d74d063 100644 --- a/pandas/tests/series/methods/test_asof.py +++ b/pandas/tests/series/methods/test_asof.py @@ -65,8 +65,8 @@ def test_scalar(self): rng = date_range("1/1/1990", periods=N, freq="53s") # Explicit cast to float avoid implicit cast when setting nan ts = Series(np.arange(N), index=rng, dtype="float") - ts.iloc[5:10] = np.NaN - ts.iloc[15:20] = np.NaN + ts.iloc[5:10] = np.nan + ts.iloc[15:20] = np.nan val1 = ts.asof(ts.index[7]) val2 = ts.asof(ts.index[19]) diff --git a/pandas/tests/series/methods/test_combine_first.py b/pandas/tests/series/methods/test_combine_first.py index c7ca73da9ae66..d2d8eab1cb38b 100644 --- a/pandas/tests/series/methods/test_combine_first.py +++ b/pandas/tests/series/methods/test_combine_first.py @@ -36,7 +36,7 @@ def test_combine_first(self): series = Series(values, index=tm.makeIntIndex(20)) series_copy = series * 2 - series_copy[::2] = np.NaN + series_copy[::2] = np.nan # nothing used from the input combined = series.combine_first(series_copy) @@ -70,14 +70,14 @@ def test_combine_first(self): tm.assert_series_equal(ser, result) def test_combine_first_dt64(self): - s0 = to_datetime(Series(["2010", np.NaN])) - s1 = to_datetime(Series([np.NaN, "2011"])) + s0 = to_datetime(Series(["2010", np.nan])) + s1 = to_datetime(Series([np.nan, "2011"])) rs = s0.combine_first(s1) xp = to_datetime(Series(["2010", "2011"])) tm.assert_series_equal(rs, xp) - s0 = to_datetime(Series(["2010", np.NaN])) - s1 = Series([np.NaN, "2011"]) + s0 = to_datetime(Series(["2010", np.nan])) + s1 = Series([np.nan, "2011"]) rs = s0.combine_first(s1) xp = Series([datetime(2010, 1, 1), "2011"], dtype="datetime64[ns]") diff --git a/pandas/tests/series/methods/test_copy.py b/pandas/tests/series/methods/test_copy.py index 5ebf45090d7b8..77600e0e7d293 100644 --- a/pandas/tests/series/methods/test_copy.py +++ b/pandas/tests/series/methods/test_copy.py @@ -27,7 +27,7 @@ def test_copy(self, deep, using_copy_on_write): else: assert not np.may_share_memory(ser.values, ser2.values) - ser2[::2] = np.NaN + ser2[::2] = np.nan if deep is not False or using_copy_on_write: # Did not modify original Series diff --git a/pandas/tests/series/methods/test_count.py b/pandas/tests/series/methods/test_count.py index 90984a2e65cba..9ba163f347198 100644 --- a/pandas/tests/series/methods/test_count.py +++ b/pandas/tests/series/methods/test_count.py @@ -12,7 +12,7 @@ class TestSeriesCount: def test_count(self, datetime_series): assert datetime_series.count() == len(datetime_series) - datetime_series[::2] = np.NaN + datetime_series[::2] = np.nan assert datetime_series.count() == np.isfinite(datetime_series).sum() diff --git a/pandas/tests/series/methods/test_drop_duplicates.py b/pandas/tests/series/methods/test_drop_duplicates.py index 7e4503be2ec47..96c2e1ba6d9bb 100644 --- a/pandas/tests/series/methods/test_drop_duplicates.py +++ b/pandas/tests/series/methods/test_drop_duplicates.py @@ -71,7 +71,7 @@ def test_drop_duplicates_no_duplicates(any_numpy_dtype, keep, values): class TestSeriesDropDuplicates: @pytest.fixture( - params=["int_", "uint", "float_", "unicode_", "timedelta64[h]", "datetime64[D]"] + params=["int_", "uint", "float64", "str_", "timedelta64[h]", "datetime64[D]"] ) def dtype(self, request): return request.param diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 96c3674541e6b..46bc14da59eb0 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -75,7 +75,7 @@ def test_fillna(self): tm.assert_series_equal(ts, ts.fillna(method="ffill")) - ts.iloc[2] = np.NaN + ts.iloc[2] = np.nan exp = Series([0.0, 1.0, 1.0, 3.0, 4.0], index=ts.index) tm.assert_series_equal(ts.fillna(method="ffill"), exp) @@ -881,7 +881,7 @@ def test_fillna_bug(self): def test_ffill(self): ts = Series([0.0, 1.0, 2.0, 3.0, 4.0], index=tm.makeDateIndex(5)) - ts.iloc[2] = np.NaN + ts.iloc[2] = np.nan tm.assert_series_equal(ts.ffill(), ts.fillna(method="ffill")) def test_ffill_mixed_dtypes_without_missing_data(self): @@ -892,7 +892,7 @@ def test_ffill_mixed_dtypes_without_missing_data(self): def test_bfill(self): ts = Series([0.0, 1.0, 2.0, 3.0, 4.0], index=tm.makeDateIndex(5)) - ts.iloc[2] = np.NaN + ts.iloc[2] = np.nan tm.assert_series_equal(ts.bfill(), ts.fillna(method="bfill")) def test_pad_nan(self): diff --git a/pandas/tests/series/methods/test_interpolate.py b/pandas/tests/series/methods/test_interpolate.py index a984cd16997aa..619690f400d98 100644 --- a/pandas/tests/series/methods/test_interpolate.py +++ b/pandas/tests/series/methods/test_interpolate.py @@ -94,7 +94,7 @@ def test_interpolate(self, datetime_series): ts = Series(np.arange(len(datetime_series), dtype=float), datetime_series.index) ts_copy = ts.copy() - ts_copy[5:10] = np.NaN + ts_copy[5:10] = np.nan linear_interp = ts_copy.interpolate(method="linear") tm.assert_series_equal(linear_interp, ts) @@ -104,7 +104,7 @@ def test_interpolate(self, datetime_series): ).astype(float) ord_ts_copy = ord_ts.copy() - ord_ts_copy[5:10] = np.NaN + ord_ts_copy[5:10] = np.nan time_interp = ord_ts_copy.interpolate(method="time") tm.assert_series_equal(time_interp, ord_ts) @@ -112,7 +112,7 @@ def test_interpolate(self, datetime_series): def test_interpolate_time_raises_for_non_timeseries(self): # When method='time' is used on a non-TimeSeries that contains a null # value, a ValueError should be raised. - non_ts = Series([0, 1, 2, np.NaN]) + non_ts = Series([0, 1, 2, np.nan]) msg = "time-weighted interpolation only works on Series.* with a DatetimeIndex" with pytest.raises(ValueError, match=msg): non_ts.interpolate(method="time") diff --git a/pandas/tests/series/methods/test_map.py b/pandas/tests/series/methods/test_map.py index 00d1ad99332e9..783e18e541ad8 100644 --- a/pandas/tests/series/methods/test_map.py +++ b/pandas/tests/series/methods/test_map.py @@ -104,7 +104,7 @@ def test_map_series_stringdtype(any_string_dtype): @pytest.mark.parametrize( "data, expected_dtype", - [(["1-1", "1-1", np.NaN], "category"), (["1-1", "1-2", np.NaN], object)], + [(["1-1", "1-1", np.nan], "category"), (["1-1", "1-2", np.nan], object)], ) def test_map_categorical_with_nan_values(data, expected_dtype): # GH 20714 bug fixed in: GH 24275 @@ -114,7 +114,7 @@ def func(val): s = Series(data, dtype="category") result = s.map(func, na_action="ignore") - expected = Series(["1", "1", np.NaN], dtype=expected_dtype) + expected = Series(["1", "1", np.nan], dtype=expected_dtype) tm.assert_series_equal(result, expected) @@ -229,11 +229,11 @@ def test_map_int(): left = Series({"a": 1.0, "b": 2.0, "c": 3.0, "d": 4}) right = Series({1: 11, 2: 22, 3: 33}) - assert left.dtype == np.float_ + assert left.dtype == np.float64 assert issubclass(right.dtype.type, np.integer) merged = left.map(right) - assert merged.dtype == np.float_ + assert merged.dtype == np.float64 assert isna(merged["d"]) assert not isna(merged["c"]) diff --git a/pandas/tests/series/methods/test_pct_change.py b/pandas/tests/series/methods/test_pct_change.py index 38a42062b275e..4dabf7b87e2cd 100644 --- a/pandas/tests/series/methods/test_pct_change.py +++ b/pandas/tests/series/methods/test_pct_change.py @@ -40,7 +40,7 @@ def test_pct_change_with_duplicate_axis(self): result = Series(range(5), common_idx).pct_change(freq="B") # the reason that the expected should be like this is documented at PR 28681 - expected = Series([np.NaN, np.inf, np.NaN, np.NaN, 3.0], common_idx) + expected = Series([np.nan, np.inf, np.nan, np.nan, 3.0], common_idx) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/methods/test_rank.py b/pandas/tests/series/methods/test_rank.py index 766a2415d89fb..24cf97c05c0a8 100644 --- a/pandas/tests/series/methods/test_rank.py +++ b/pandas/tests/series/methods/test_rank.py @@ -185,7 +185,7 @@ def test_rank_categorical(self): # Test na_option for rank data na_ser = Series( - ["first", "second", "third", "fourth", "fifth", "sixth", np.NaN] + ["first", "second", "third", "fourth", "fifth", "sixth", np.nan] ).astype( CategoricalDtype( ["first", "second", "third", "fourth", "fifth", "sixth", "seventh"], @@ -195,7 +195,7 @@ def test_rank_categorical(self): exp_top = Series([2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0]) exp_bot = Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]) - exp_keep = Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, np.NaN]) + exp_keep = Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, np.nan]) tm.assert_series_equal(na_ser.rank(na_option="top"), exp_top) tm.assert_series_equal(na_ser.rank(na_option="bottom"), exp_bot) @@ -204,7 +204,7 @@ def test_rank_categorical(self): # Test na_option for rank data with ascending False exp_top = Series([7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0]) exp_bot = Series([6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 7.0]) - exp_keep = Series([6.0, 5.0, 4.0, 3.0, 2.0, 1.0, np.NaN]) + exp_keep = Series([6.0, 5.0, 4.0, 3.0, 2.0, 1.0, np.nan]) tm.assert_series_equal(na_ser.rank(na_option="top", ascending=False), exp_top) tm.assert_series_equal( @@ -223,12 +223,12 @@ def test_rank_categorical(self): na_ser.rank(na_option=True, ascending=False) # Test with pct=True - na_ser = Series(["first", "second", "third", "fourth", np.NaN]).astype( + na_ser = Series(["first", "second", "third", "fourth", np.nan]).astype( CategoricalDtype(["first", "second", "third", "fourth"], True) ) exp_top = Series([0.4, 0.6, 0.8, 1.0, 0.2]) exp_bot = Series([0.2, 0.4, 0.6, 0.8, 1.0]) - exp_keep = Series([0.25, 0.5, 0.75, 1.0, np.NaN]) + exp_keep = Series([0.25, 0.5, 0.75, 1.0, np.nan]) tm.assert_series_equal(na_ser.rank(na_option="top", pct=True), exp_top) tm.assert_series_equal(na_ser.rank(na_option="bottom", pct=True), exp_bot) diff --git a/pandas/tests/series/methods/test_reindex.py b/pandas/tests/series/methods/test_reindex.py index 52446f96009d5..2ab1cd13a31d8 100644 --- a/pandas/tests/series/methods/test_reindex.py +++ b/pandas/tests/series/methods/test_reindex.py @@ -194,7 +194,7 @@ def test_reindex_int(datetime_series): reindexed_int = int_ts.reindex(datetime_series.index) # if NaNs introduced - assert reindexed_int.dtype == np.float_ + assert reindexed_int.dtype == np.float64 # NO NaNs introduced reindexed_int = int_ts.reindex(int_ts.index[::2]) @@ -425,11 +425,11 @@ def test_reindexing_with_float64_NA_log(): s = Series([1.0, NA], dtype=Float64Dtype()) s_reindex = s.reindex(range(3)) result = s_reindex.values._data - expected = np.array([1, np.NaN, np.NaN]) + expected = np.array([1, np.nan, np.nan]) tm.assert_numpy_array_equal(result, expected) with tm.assert_produces_warning(None): result_log = np.log(s_reindex) - expected_log = Series([0, np.NaN, np.NaN], dtype=Float64Dtype()) + expected_log = Series([0, np.nan, np.nan], dtype=Float64Dtype()) tm.assert_series_equal(result_log, expected_log) diff --git a/pandas/tests/series/methods/test_sort_values.py b/pandas/tests/series/methods/test_sort_values.py index c3e074dc68c82..4808272879071 100644 --- a/pandas/tests/series/methods/test_sort_values.py +++ b/pandas/tests/series/methods/test_sort_values.py @@ -18,7 +18,7 @@ def test_sort_values(self, datetime_series, using_copy_on_write): tm.assert_series_equal(expected, result) ts = datetime_series.copy() - ts[:5] = np.NaN + ts[:5] = np.nan vals = ts.values result = ts.sort_values() diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 331afc4345616..611f4a7f790a6 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -165,7 +165,7 @@ def test_constructor(self, datetime_series): assert id(datetime_series.index) == id(derived.index) # Mixed type Series - mixed = Series(["hello", np.NaN], index=[0, 1]) + mixed = Series(["hello", np.nan], index=[0, 1]) assert mixed.dtype == np.object_ assert np.isnan(mixed[1]) @@ -1464,8 +1464,8 @@ def test_fromDict(self): assert series.dtype == np.float64 def test_fromValue(self, datetime_series): - nans = Series(np.NaN, index=datetime_series.index, dtype=np.float64) - assert nans.dtype == np.float_ + nans = Series(np.nan, index=datetime_series.index, dtype=np.float64) + assert nans.dtype == np.float64 assert len(nans) == len(datetime_series) strings = Series("foo", index=datetime_series.index) diff --git a/pandas/tests/series/test_cumulative.py b/pandas/tests/series/test_cumulative.py index 4c5fd2d44e4f4..e6f7b2a5e69e0 100644 --- a/pandas/tests/series/test_cumulative.py +++ b/pandas/tests/series/test_cumulative.py @@ -31,7 +31,7 @@ def test_datetime_series(self, datetime_series, func): # with missing values ts = datetime_series.copy() - ts[::2] = np.NaN + ts[::2] = np.nan result = func(ts)[1::2] expected = func(np.array(ts.dropna())) @@ -47,7 +47,7 @@ def test_cummin_cummax(self, datetime_series, method): tm.assert_numpy_array_equal(result, expected) ts = datetime_series.copy() - ts[::2] = np.NaN + ts[::2] = np.nan result = getattr(ts, method)()[1::2] expected = ufunc(ts.dropna()) diff --git a/pandas/tests/series/test_logical_ops.py b/pandas/tests/series/test_logical_ops.py index 4dab3e8f62598..26046ef9ba295 100644 --- a/pandas/tests/series/test_logical_ops.py +++ b/pandas/tests/series/test_logical_ops.py @@ -93,7 +93,7 @@ def test_logical_operators_int_dtype_with_float(self): msg = "Cannot perform.+with a dtyped.+array and scalar of type" with pytest.raises(TypeError, match=msg): - s_0123 & np.NaN + s_0123 & np.nan with pytest.raises(TypeError, match=msg): s_0123 & 3.14 msg = "unsupported operand type.+for &:" @@ -149,11 +149,11 @@ def test_logical_operators_int_dtype_with_object(self): # GH#9016: support bitwise op for integer types s_0123 = Series(range(4), dtype="int64") - result = s_0123 & Series([False, np.NaN, False, False]) + result = s_0123 & Series([False, np.nan, False, False]) expected = Series([False] * 4) tm.assert_series_equal(result, expected) - s_abNd = Series(["a", "b", np.NaN, "d"]) + s_abNd = Series(["a", "b", np.nan, "d"]) with pytest.raises(TypeError, match="unsupported.* 'int' and 'str'"): s_0123 & s_abNd diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 9f17f6d86cf93..cafc69c4d0f20 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -84,7 +84,7 @@ def test_logical_range_select(self, datetime_series): def test_valid(self, datetime_series): ts = datetime_series.copy() ts.index = ts.index._with_freq(None) - ts[::2] = np.NaN + ts[::2] = np.nan result = ts.dropna() assert len(result) == ts.count() diff --git a/pandas/tests/series/test_repr.py b/pandas/tests/series/test_repr.py index 4c92b5694c43b..f294885fb8f4d 100644 --- a/pandas/tests/series/test_repr.py +++ b/pandas/tests/series/test_repr.py @@ -83,7 +83,7 @@ def test_string(self, string_series): str(string_series.astype(int)) # with NaNs - string_series[5:7] = np.NaN + string_series[5:7] = np.nan str(string_series) def test_object(self, object_series): diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py index 76784ec726afe..a0062d2b6dd44 100644 --- a/pandas/tests/test_nanops.py +++ b/pandas/tests/test_nanops.py @@ -323,7 +323,7 @@ def check_fun_data( res = testfunc(testarval, axis=axis, skipna=skipna, **kwargs) if ( - isinstance(targ, np.complex_) + isinstance(targ, np.complex128) and isinstance(res, float) and np.isnan(targ) and np.isnan(res) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 5e51edfee17f1..93fe9b05adb4f 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -1570,8 +1570,8 @@ def test_convert_object_to_datetime_with_cache( (Series([""] * 60), Series([NaT] * 60, dtype="datetime64[ns]")), (Series([pd.NA] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), (Series([pd.NA] * 60), Series([NaT] * 60, dtype="datetime64[ns]")), - (Series([np.NaN] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), - (Series([np.NaN] * 60), Series([NaT] * 60, dtype="datetime64[ns]")), + (Series([np.nan] * 20), Series([NaT] * 20, dtype="datetime64[ns]")), + (Series([np.nan] * 60), Series([NaT] * 60, dtype="datetime64[ns]")), ), ) def test_to_datetime_converts_null_like_to_nat(self, cache, input, expected): diff --git a/pandas/tests/util/test_assert_almost_equal.py b/pandas/tests/util/test_assert_almost_equal.py index a86302f158005..8527efdbf7867 100644 --- a/pandas/tests/util/test_assert_almost_equal.py +++ b/pandas/tests/util/test_assert_almost_equal.py @@ -293,7 +293,7 @@ def test_assert_almost_equal_null(): _assert_almost_equal_both(None, None) -@pytest.mark.parametrize("a,b", [(None, np.NaN), (None, 0), (np.NaN, 0)]) +@pytest.mark.parametrize("a,b", [(None, np.nan), (None, 0), (np.nan, 0)]) def test_assert_not_almost_equal_null(a, b): _assert_not_almost_equal(a, b) diff --git a/pandas/tests/window/conftest.py b/pandas/tests/window/conftest.py index 2dd4458172593..73ab470ab97a7 100644 --- a/pandas/tests/window/conftest.py +++ b/pandas/tests/window/conftest.py @@ -126,7 +126,7 @@ def series(): """Make mocked series as fixture.""" arr = np.random.default_rng(2).standard_normal(100) locs = np.arange(20, 40) - arr[locs] = np.NaN + arr[locs] = np.nan series = Series(arr, index=bdate_range(datetime(2009, 1, 1), periods=100)) return series diff --git a/pandas/tests/window/test_api.py b/pandas/tests/window/test_api.py index d901fe58950e3..33858e10afd75 100644 --- a/pandas/tests/window/test_api.py +++ b/pandas/tests/window/test_api.py @@ -223,9 +223,9 @@ def test_count_nonnumeric_types(step): Period("2012-02"), Period("2012-03"), ], - "fl_inf": [1.0, 2.0, np.Inf], - "fl_nan": [1.0, 2.0, np.NaN], - "str_nan": ["aa", "bb", np.NaN], + "fl_inf": [1.0, 2.0, np.inf], + "fl_nan": [1.0, 2.0, np.nan], + "str_nan": ["aa", "bb", np.nan], "dt_nat": dt_nat_col, "periods_nat": [ Period("2012-01"), diff --git a/pandas/tests/window/test_apply.py b/pandas/tests/window/test_apply.py index 6af5a41e96e0a..4e4eca6e772e7 100644 --- a/pandas/tests/window/test_apply.py +++ b/pandas/tests/window/test_apply.py @@ -184,8 +184,8 @@ def numpysum(x, par): def test_nans(raw): obj = Series(np.random.default_rng(2).standard_normal(50)) - obj[:10] = np.NaN - obj[-10:] = np.NaN + obj[:10] = np.nan + obj[-10:] = np.nan result = obj.rolling(50, min_periods=30).apply(f, raw=raw) tm.assert_almost_equal(result.iloc[-1], np.mean(obj[10:-10])) @@ -210,12 +210,12 @@ def test_nans(raw): def test_center(raw): obj = Series(np.random.default_rng(2).standard_normal(50)) - obj[:10] = np.NaN - obj[-10:] = np.NaN + obj[:10] = np.nan + obj[-10:] = np.nan result = obj.rolling(20, min_periods=15, center=True).apply(f, raw=raw) expected = ( - concat([obj, Series([np.NaN] * 9)]) + concat([obj, Series([np.nan] * 9)]) .rolling(20, min_periods=15) .apply(f, raw=raw) .iloc[9:] diff --git a/pandas/tests/window/test_ewm.py b/pandas/tests/window/test_ewm.py index 45d481fdd2e44..c5c395414b450 100644 --- a/pandas/tests/window/test_ewm.py +++ b/pandas/tests/window/test_ewm.py @@ -417,7 +417,7 @@ def test_ewm_alpha(): # GH 10789 arr = np.random.default_rng(2).standard_normal(100) locs = np.arange(20, 40) - arr[locs] = np.NaN + arr[locs] = np.nan s = Series(arr) a = s.ewm(alpha=0.61722699889169674).mean() @@ -433,7 +433,7 @@ def test_ewm_domain_checks(): # GH 12492 arr = np.random.default_rng(2).standard_normal(100) locs = np.arange(20, 40) - arr[locs] = np.NaN + arr[locs] = np.nan s = Series(arr) msg = "comass must satisfy: comass >= 0" @@ -484,8 +484,8 @@ def test_ew_empty_series(method): def test_ew_min_periods(min_periods, name): # excluding NaNs correctly arr = np.random.default_rng(2).standard_normal(50) - arr[:10] = np.NaN - arr[-10:] = np.NaN + arr[:10] = np.nan + arr[-10:] = np.nan s = Series(arr) # check min_periods @@ -515,11 +515,11 @@ def test_ew_min_periods(min_periods, name): else: # ewm.std, ewm.var with bias=False require at least # two values - tm.assert_series_equal(result, Series([np.NaN])) + tm.assert_series_equal(result, Series([np.nan])) # pass in ints result2 = getattr(Series(np.arange(50)).ewm(span=10), name)() - assert result2.dtype == np.float_ + assert result2.dtype == np.float64 @pytest.mark.parametrize("name", ["cov", "corr"]) @@ -527,8 +527,8 @@ def test_ewm_corr_cov(name): A = Series(np.random.default_rng(2).standard_normal(50), index=range(50)) B = A[2:] + np.random.default_rng(2).standard_normal(48) - A[:10] = np.NaN - B.iloc[-10:] = np.NaN + A[:10] = np.nan + B.iloc[-10:] = np.nan result = getattr(A.ewm(com=20, min_periods=5), name)(B) assert np.isnan(result.values[:14]).all() @@ -542,8 +542,8 @@ def test_ewm_corr_cov_min_periods(name, min_periods): A = Series(np.random.default_rng(2).standard_normal(50), index=range(50)) B = A[2:] + np.random.default_rng(2).standard_normal(48) - A[:10] = np.NaN - B.iloc[-10:] = np.NaN + A[:10] = np.nan + B.iloc[-10:] = np.nan result = getattr(A.ewm(com=20, min_periods=min_periods), name)(B) # binary functions (ewmcov, ewmcorr) with bias=False require at @@ -560,13 +560,13 @@ def test_ewm_corr_cov_min_periods(name, min_periods): result = getattr(Series([1.0]).ewm(com=50, min_periods=min_periods), name)( Series([1.0]) ) - tm.assert_series_equal(result, Series([np.NaN])) + tm.assert_series_equal(result, Series([np.nan])) @pytest.mark.parametrize("name", ["cov", "corr"]) def test_different_input_array_raise_exception(name): A = Series(np.random.default_rng(2).standard_normal(50), index=range(50)) - A[:10] = np.NaN + A[:10] = np.nan msg = "other must be a DataFrame or Series" # exception raised is Exception diff --git a/pandas/tests/window/test_pairwise.py b/pandas/tests/window/test_pairwise.py index 8dac6d271510a..b6f2365afb457 100644 --- a/pandas/tests/window/test_pairwise.py +++ b/pandas/tests/window/test_pairwise.py @@ -410,7 +410,7 @@ def test_cov_mulittindex(self): expected = DataFrame( np.vstack( ( - np.full((8, 8), np.NaN), + np.full((8, 8), np.nan), np.full((8, 8), 32.000000), np.full((8, 8), 63.881919), ) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index 4df20282bbfa6..70b7534b296f3 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -142,7 +142,7 @@ def test_constructor_timedelta_window_and_minperiods(window, raw): index=date_range("2017-08-08", periods=n, freq="D"), ) expected = DataFrame( - {"value": np.append([np.NaN, 1.0], np.arange(3.0, 27.0, 3))}, + {"value": np.append([np.nan, 1.0], np.arange(3.0, 27.0, 3))}, index=date_range("2017-08-08", periods=n, freq="D"), ) result_roll_sum = df.rolling(window=window, min_periods=2).sum() @@ -1461,15 +1461,15 @@ def test_rolling_mean_all_nan_window_floating_artifacts(start, exp_values): 0.03, 0.03, 0.001, - np.NaN, + np.nan, 0.002, 0.008, - np.NaN, - np.NaN, - np.NaN, - np.NaN, - np.NaN, - np.NaN, + np.nan, + np.nan, + np.nan, + np.nan, + np.nan, + np.nan, 0.005, 0.2, ] @@ -1480,8 +1480,8 @@ def test_rolling_mean_all_nan_window_floating_artifacts(start, exp_values): 0.005, 0.005, 0.008, - np.NaN, - np.NaN, + np.nan, + np.nan, 0.005, 0.102500, ] @@ -1495,7 +1495,7 @@ def test_rolling_mean_all_nan_window_floating_artifacts(start, exp_values): def test_rolling_sum_all_nan_window_floating_artifacts(): # GH#41053 - df = DataFrame([0.002, 0.008, 0.005, np.NaN, np.NaN, np.NaN]) + df = DataFrame([0.002, 0.008, 0.005, np.nan, np.nan, np.nan]) result = df.rolling(3, min_periods=0).sum() expected = DataFrame([0.002, 0.010, 0.015, 0.013, 0.005, 0.0]) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/window/test_rolling_functions.py b/pandas/tests/window/test_rolling_functions.py index bc0b3e496038c..940f0845befa2 100644 --- a/pandas/tests/window/test_rolling_functions.py +++ b/pandas/tests/window/test_rolling_functions.py @@ -150,8 +150,8 @@ def test_time_rule_frame(raw, frame, compare_func, roll_func, kwargs, minp): ) def test_nans(compare_func, roll_func, kwargs): obj = Series(np.random.default_rng(2).standard_normal(50)) - obj[:10] = np.NaN - obj[-10:] = np.NaN + obj[:10] = np.nan + obj[-10:] = np.nan result = getattr(obj.rolling(50, min_periods=30), roll_func)(**kwargs) tm.assert_almost_equal(result.iloc[-1], compare_func(obj[10:-10])) @@ -177,8 +177,8 @@ def test_nans(compare_func, roll_func, kwargs): def test_nans_count(): obj = Series(np.random.default_rng(2).standard_normal(50)) - obj[:10] = np.NaN - obj[-10:] = np.NaN + obj[:10] = np.nan + obj[-10:] = np.nan result = obj.rolling(50, min_periods=30).count() tm.assert_almost_equal( result.iloc[-1], np.isfinite(obj[10:-10]).astype(float).sum() @@ -241,15 +241,15 @@ def test_min_periods_count(series, step): ) def test_center(roll_func, kwargs, minp): obj = Series(np.random.default_rng(2).standard_normal(50)) - obj[:10] = np.NaN - obj[-10:] = np.NaN + obj[:10] = np.nan + obj[-10:] = np.nan result = getattr(obj.rolling(20, min_periods=minp, center=True), roll_func)( **kwargs ) expected = ( getattr( - concat([obj, Series([np.NaN] * 9)]).rolling(20, min_periods=minp), roll_func + concat([obj, Series([np.nan] * 9)]).rolling(20, min_periods=minp), roll_func )(**kwargs) .iloc[9:] .reset_index(drop=True) diff --git a/pandas/tests/window/test_rolling_quantile.py b/pandas/tests/window/test_rolling_quantile.py index 32296ae3f2470..d5a7010923563 100644 --- a/pandas/tests/window/test_rolling_quantile.py +++ b/pandas/tests/window/test_rolling_quantile.py @@ -89,8 +89,8 @@ def test_time_rule_frame(raw, frame, q): def test_nans(q): compare_func = partial(scoreatpercentile, per=q) obj = Series(np.random.default_rng(2).standard_normal(50)) - obj[:10] = np.NaN - obj[-10:] = np.NaN + obj[:10] = np.nan + obj[-10:] = np.nan result = obj.rolling(50, min_periods=30).quantile(q) tm.assert_almost_equal(result.iloc[-1], compare_func(obj[10:-10])) @@ -128,12 +128,12 @@ def test_min_periods(series, minp, q, step): @pytest.mark.parametrize("q", [0.0, 0.1, 0.5, 0.9, 1.0]) def test_center(q): obj = Series(np.random.default_rng(2).standard_normal(50)) - obj[:10] = np.NaN - obj[-10:] = np.NaN + obj[:10] = np.nan + obj[-10:] = np.nan result = obj.rolling(20, center=True).quantile(q) expected = ( - concat([obj, Series([np.NaN] * 9)]) + concat([obj, Series([np.nan] * 9)]) .rolling(20) .quantile(q) .iloc[9:] diff --git a/pandas/tests/window/test_rolling_skew_kurt.py b/pandas/tests/window/test_rolling_skew_kurt.py index ada726401c4a0..79c14f243e7cc 100644 --- a/pandas/tests/window/test_rolling_skew_kurt.py +++ b/pandas/tests/window/test_rolling_skew_kurt.py @@ -79,8 +79,8 @@ def test_nans(sp_func, roll_func): compare_func = partial(getattr(sp_stats, sp_func), bias=False) obj = Series(np.random.default_rng(2).standard_normal(50)) - obj[:10] = np.NaN - obj[-10:] = np.NaN + obj[:10] = np.nan + obj[-10:] = np.nan result = getattr(obj.rolling(50, min_periods=30), roll_func)() tm.assert_almost_equal(result.iloc[-1], compare_func(obj[10:-10])) @@ -122,12 +122,12 @@ def test_min_periods(series, minp, roll_func, step): @pytest.mark.parametrize("roll_func", ["kurt", "skew"]) def test_center(roll_func): obj = Series(np.random.default_rng(2).standard_normal(50)) - obj[:10] = np.NaN - obj[-10:] = np.NaN + obj[:10] = np.nan + obj[-10:] = np.nan result = getattr(obj.rolling(20, center=True), roll_func)() expected = ( - getattr(concat([obj, Series([np.NaN] * 9)]).rolling(20), roll_func)() + getattr(concat([obj, Series([np.nan] * 9)]).rolling(20), roll_func)() .iloc[9:] .reset_index(drop=True) ) @@ -170,14 +170,14 @@ def test_center_reindex_frame(frame, roll_func): def test_rolling_skew_edge_cases(step): - expected = Series([np.NaN] * 4 + [0.0])[::step] + expected = Series([np.nan] * 4 + [0.0])[::step] # yields all NaN (0 variance) d = Series([1] * 5) x = d.rolling(window=5, step=step).skew() # index 4 should be 0 as it contains 5 same obs tm.assert_series_equal(expected, x) - expected = Series([np.NaN] * 5)[::step] + expected = Series([np.nan] * 5)[::step] # yields all NaN (window too small) d = Series(np.random.default_rng(2).standard_normal(5)) x = d.rolling(window=2, step=step).skew() @@ -185,13 +185,13 @@ def test_rolling_skew_edge_cases(step): # yields [NaN, NaN, NaN, 0.177994, 1.548824] d = Series([-1.50837035, -0.1297039, 0.19501095, 1.73508164, 0.41941401]) - expected = Series([np.NaN, np.NaN, np.NaN, 0.177994, 1.548824])[::step] + expected = Series([np.nan, np.nan, np.nan, 0.177994, 1.548824])[::step] x = d.rolling(window=4, step=step).skew() tm.assert_series_equal(expected, x) def test_rolling_kurt_edge_cases(step): - expected = Series([np.NaN] * 4 + [-3.0])[::step] + expected = Series([np.nan] * 4 + [-3.0])[::step] # yields all NaN (0 variance) d = Series([1] * 5) @@ -199,14 +199,14 @@ def test_rolling_kurt_edge_cases(step): tm.assert_series_equal(expected, x) # yields all NaN (window too small) - expected = Series([np.NaN] * 5)[::step] + expected = Series([np.nan] * 5)[::step] d = Series(np.random.default_rng(2).standard_normal(5)) x = d.rolling(window=3, step=step).kurt() tm.assert_series_equal(expected, x) # yields [NaN, NaN, NaN, 1.224307, 2.671499] d = Series([-1.50837035, -0.1297039, 0.19501095, 1.73508164, 0.41941401]) - expected = Series([np.NaN, np.NaN, np.NaN, 1.224307, 2.671499])[::step] + expected = Series([np.nan, np.nan, np.nan, 1.224307, 2.671499])[::step] x = d.rolling(window=4, step=step).kurt() tm.assert_series_equal(expected, x) diff --git a/pandas/tests/window/test_win_type.py b/pandas/tests/window/test_win_type.py index 2ca02fef796ed..5052019ddb726 100644 --- a/pandas/tests/window/test_win_type.py +++ b/pandas/tests/window/test_win_type.py @@ -666,7 +666,7 @@ def test_weighted_var_big_window_no_segfault(win_types, center): pytest.importorskip("scipy") x = Series(0) result = x.rolling(window=16, center=center, win_type=win_types).var() - expected = Series(np.NaN) + expected = Series(np.nan) tm.assert_series_equal(result, expected)