diff --git a/pandas-stubs/core/resample.pyi b/pandas-stubs/core/resample.pyi index 54c748a67..9f52c69ef 100644 --- a/pandas-stubs/core/resample.pyi +++ b/pandas-stubs/core/resample.pyi @@ -92,19 +92,6 @@ class Resampler(BaseGroupBy[NDFrameT]): def nearest(self, limit: int | None = ...) -> NDFrameT: ... @final def bfill(self, limit: int | None = ...) -> NDFrameT: ... - @overload - def interpolate( - self, - method: InterpolateOptions = ..., - *, - axis: Axis = ..., - limit: int | None = ..., - inplace: Literal[True], - limit_direction: Literal["forward", "backward", "both"] = ..., - limit_area: Literal["inside", "outside"] | None = ..., - **kwargs: Any, - ) -> None: ... - @overload def interpolate( self, method: InterpolateOptions = ..., diff --git a/tests/arrays/test_extension_array.py b/tests/arrays/test_extension_array.py index cd771dd23..780e4fa40 100644 --- a/tests/arrays/test_extension_array.py +++ b/tests/arrays/test_extension_array.py @@ -14,6 +14,7 @@ from tests import ( check, np_1darray, + np_1darray_intp, ) @@ -50,6 +51,6 @@ def test_ea_common() -> None: check(assert_type(arr.view(), IntegerArray), IntegerArray) check(assert_type(arr.searchsorted(1), np.intp), np.intp) - check(assert_type(arr.searchsorted([1]), "np_1darray[np.intp]"), np_1darray) + check(assert_type(arr.searchsorted([1]), np_1darray_intp), np_1darray_intp) check(assert_type(arr.searchsorted(1, side="left"), np.intp), np.intp) check(assert_type(arr.searchsorted(1, sorter=[1, 0, 2]), np.intp), np.intp) diff --git a/tests/indexes/test_categoricalindex.py b/tests/indexes/test_categoricalindex.py index 7a9990582..dff2b7db8 100644 --- a/tests/indexes/test_categoricalindex.py +++ b/tests/indexes/test_categoricalindex.py @@ -1,6 +1,5 @@ from __future__ import annotations -import numpy as np import pandas as pd from typing_extensions import ( assert_type, @@ -8,7 +7,7 @@ from tests import ( check, - np_1darray, + np_1darray_intp, ) @@ -23,7 +22,7 @@ def test_categoricalindex_unique() -> None: def test_categoricalindex_reindex() -> None: ci = pd.CategoricalIndex(["a", "b"]) check( - assert_type(ci.reindex([0, 1]), tuple[pd.Index, np_1darray[np.intp] | None]), + assert_type(ci.reindex([0, 1]), tuple[pd.Index, np_1darray_intp | None]), tuple, ) diff --git a/tests/indexes/test_datetime_index.py b/tests/indexes/test_datetime_index.py index 3c87bb1bd..d91442944 100644 --- a/tests/indexes/test_datetime_index.py +++ b/tests/indexes/test_datetime_index.py @@ -8,7 +8,8 @@ from tests import ( check, - np_1darray, + np_1darray_bool, + np_1darray_intp, ) @@ -34,10 +35,10 @@ def test_index_relops() -> None: check(assert_type(data[idx > x], pd.DatetimeIndex), pd.DatetimeIndex) ind = pd.Index([1, 2, 3]) - check(assert_type(ind <= 2, np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type(ind < 2, np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type(ind >= 2, np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type(ind > 2, np_1darray[np.bool]), np_1darray[np.bool]) + check(assert_type(ind <= 2, np_1darray_bool), np_1darray_bool) + check(assert_type(ind < 2, np_1darray_bool), np_1darray_bool) + check(assert_type(ind >= 2, np_1darray_bool), np_1darray_bool) + check(assert_type(ind > 2, np_1darray_bool), np_1darray_bool) def test_datetime_index_constructor() -> None: @@ -92,14 +93,8 @@ def test_datetimeindex_shift() -> None: def test_datetimeindex_indexer_at_time() -> None: dti = pd.date_range("2023-01-01", "2023-02-01") - check( - assert_type(dti.indexer_at_time("10:00"), np_1darray[np.intp]), - np_1darray[np.intp], - ) - check( - assert_type(dti.indexer_at_time(time(10)), np_1darray[np.intp]), - np_1darray[np.intp], - ) + check(assert_type(dti.indexer_at_time("10:00"), np_1darray_intp), np_1darray_intp) + check(assert_type(dti.indexer_at_time(time(10)), np_1darray_intp), np_1darray_intp) def test_datetimeindex_indexer_between_time() -> None: @@ -109,13 +104,13 @@ def test_datetimeindex_indexer_between_time() -> None: dti.indexer_between_time( "10:00", time(11), include_start=False, include_end=True ), - np_1darray[np.intp], + np_1darray_intp, ), - np_1darray[np.intp], + np_1darray_intp, ) check( - assert_type(dti.indexer_between_time(time(10), "11:00"), np_1darray[np.intp]), - np_1darray[np.intp], + assert_type(dti.indexer_between_time(time(10), "11:00"), np_1darray_intp), + np_1darray_intp, ) diff --git a/tests/indexes/test_indexes.py b/tests/indexes/test_indexes.py index 8903c5666..8647f6dde 100644 --- a/tests/indexes/test_indexes.py +++ b/tests/indexes/test_indexes.py @@ -28,6 +28,9 @@ TYPE_CHECKING_INVALID_USAGE, check, np_1darray, + np_1darray_bool, + np_1darray_int64, + np_1darray_intp, np_ndarray_dt, pytest_warns_bounded, ) @@ -48,13 +51,13 @@ def test_index_duplicated() -> None: df = pd.DataFrame({"x": [1, 2, 3, 4]}, index=pd.Index([1, 2, 3, 2])) ind = df.index duplicated = ind.duplicated("first") - check(assert_type(duplicated, np_1darray[np.bool]), np_1darray[np.bool]) + check(assert_type(duplicated, np_1darray_bool), np_1darray_bool) def test_index_isin() -> None: ind = pd.Index([1, 2, 3, 4, 5]) isin = ind.isin([2, 4]) - check(assert_type(isin, np_1darray[np.bool]), np_1darray[np.bool]) + check(assert_type(isin, np_1darray_bool), np_1darray_bool) def test_index_astype() -> None: @@ -248,11 +251,8 @@ def test_types_to_numpy() -> None: check(assert_type(idx.to_numpy(na_value=0), np_1darray), np_1darray) r_idx = pd.RangeIndex(2) - check(assert_type(r_idx.to_numpy(), np_1darray[np.int64]), np_1darray[np.int64]) - check( - assert_type(r_idx.to_numpy(na_value=0), np_1darray[np.int64]), - np_1darray[np.int64], - ) + check(assert_type(r_idx.to_numpy(), np_1darray_int64), np_1darray_int64) + check(assert_type(r_idx.to_numpy(na_value=0), np_1darray_int64), np_1darray_int64) check( assert_type(r_idx.to_numpy(dtype="int", copy=True), np_1darray), np_1darray, @@ -1191,38 +1191,32 @@ def test_datetime_operators_builtin() -> None: def test_get_loc() -> None: unique_index = pd.Index(list("abc")) check( - assert_type(unique_index.get_loc("b"), int | slice | np_1darray[np.bool]), + assert_type(unique_index.get_loc("b"), int | slice | np_1darray_bool), int, ) monotonic_index = pd.Index(list("abbc")) check( - assert_type(monotonic_index.get_loc("b"), int | slice | np_1darray[np.bool]), + assert_type(monotonic_index.get_loc("b"), int | slice | np_1darray_bool), slice, ) non_monotonic_index = pd.Index(list("abcb")) check( - assert_type( - non_monotonic_index.get_loc("b"), int | slice | np_1darray[np.bool] - ), - np_1darray[np.bool], + assert_type(non_monotonic_index.get_loc("b"), int | slice | np_1darray_bool), + np_1darray_bool, ) i1, i2, i3 = pd.Interval(0, 1), pd.Interval(1, 2), pd.Interval(0, 2) unique_interval_index = pd.IntervalIndex([i1, i2]) check( - assert_type( - unique_interval_index.get_loc(i1), int | slice | np_1darray[np.bool] - ), + assert_type(unique_interval_index.get_loc(i1), int | slice | np_1darray_bool), np.int64, ) overlap_interval_index = pd.IntervalIndex([i1, i2, i3]) check( - assert_type( - overlap_interval_index.get_loc(1), int | slice | np_1darray[np.bool] - ), - np_1darray[np.bool], + assert_type(overlap_interval_index.get_loc(1), int | slice | np_1darray_bool), + np_1darray_bool, ) @@ -1367,13 +1361,13 @@ def test_index_naming() -> None: def test_index_searchsorted() -> None: idx = pd.Index([1, 2, 3]) check(assert_type(idx.searchsorted(1), np.intp), np.intp) - check(assert_type(idx.searchsorted([1]), "np_1darray[np.intp]"), np_1darray) - check(assert_type(idx.searchsorted(range(1, 2)), "np_1darray[np.intp]"), np_1darray) + check(assert_type(idx.searchsorted([1]), np_1darray_intp), np_1darray_intp) + check(assert_type(idx.searchsorted(range(1, 2)), np_1darray_intp), np_1darray_intp) check( - assert_type(idx.searchsorted(pd.Series([1])), "np_1darray[np.intp]"), np_1darray + assert_type(idx.searchsorted(pd.Series([1])), np_1darray_intp), np_1darray_intp ) check( - assert_type(idx.searchsorted(np.array([1])), "np_1darray[np.intp]"), np_1darray + assert_type(idx.searchsorted(np.array([1])), np_1darray_intp), np_1darray_intp ) check(assert_type(idx.searchsorted(1, side="left"), np.intp), np.intp) check(assert_type(idx.searchsorted(1, sorter=[1, 0, 2]), np.intp), np.intp) @@ -1397,10 +1391,7 @@ def test_period_index_asof_locs() -> None: idx = pd.PeriodIndex(["2000", "2001"], freq="D") where = pd.DatetimeIndex(["2023-05-30 00:12:00", "2023-06-01 00:00:00"]) mask = np.ones(2, dtype=bool) - check( - assert_type(idx.asof_locs(where, mask), np_1darray[np.intp]), - np_1darray[np.intp], - ) + check(assert_type(idx.asof_locs(where, mask), np_1darray_intp), np_1darray_intp) def test_array_property() -> None: diff --git a/tests/indexes/test_rangeindex.py b/tests/indexes/test_rangeindex.py index 1b30e83ae..8cdb1b822 100644 --- a/tests/indexes/test_rangeindex.py +++ b/tests/indexes/test_rangeindex.py @@ -1,6 +1,5 @@ from __future__ import annotations -import numpy as np import pandas as pd from typing_extensions import ( assert_type, @@ -8,72 +7,48 @@ from tests import ( check, - np_1darray, + np_1darray_intp, ) def test_rangeindex_floordiv() -> None: ri = pd.RangeIndex(3) - check( - assert_type(ri // 2, "pd.Index[int]"), - pd.Index, - ) + check(assert_type(ri // 2, "pd.Index[int]"), pd.Index) def test_rangeindex_min_max() -> None: ri = pd.RangeIndex(3) - check( - assert_type(ri.min(), int), - int, - ) - check( - assert_type(ri.max(axis=0), int), - int, - ) + check(assert_type(ri.min(), int), int) + check(assert_type(ri.max(axis=0), int), int) def test_rangeindex_equals() -> None: ri = pd.RangeIndex(3) - check( - assert_type(ri.equals(ri), bool), - bool, - ) + check(assert_type(ri.equals(ri), bool), bool) def test_rangeindex_tolist() -> None: ri = pd.RangeIndex.from_range(range(3)) - check( - assert_type(ri.tolist(), list[int]), - list[int], - ) + check(assert_type(ri.tolist(), list[int]), list[int]) def test_rangeindex_get_indexer() -> None: ri = pd.RangeIndex.from_range(range(3)) - check( - assert_type(ri.get_indexer(ri), np_1darray[np.intp]), - np_1darray[np.intp], - ) + check(assert_type(ri.get_indexer(ri), np_1darray_intp), np_1darray_intp) def test_rangeindex_argsort() -> None: ri = pd.RangeIndex.from_range(range(3)) - check( - assert_type(ri.argsort(), np_1darray[np.intp]), - np_1darray[np.intp], - ) + check(assert_type(ri.argsort(), np_1darray_intp), np_1darray_intp) def test_rangeindex_join() -> None: ri = pd.RangeIndex.from_range(range(3)) - check( - assert_type(ri.join(ri), pd.Index), - pd.Index, - ) + check(assert_type(ri.join(ri), pd.Index), pd.Index) check( assert_type( ri.join(ri, return_indexers=True), - tuple[pd.Index, np_1darray[np.intp] | None, np_1darray[np.intp] | None], + tuple[pd.Index, np_1darray_intp | None, np_1darray_intp | None], ), - tuple[pd.Index, np_1darray[np.intp] | None, np_1darray[np.intp] | None], + tuple[pd.Index, np_1darray_intp | None, np_1darray_intp | None], ) diff --git a/tests/scalars/test_scalars.py b/tests/scalars/test_scalars.py index fd954051a..36c7f59fc 100644 --- a/tests/scalars/test_scalars.py +++ b/tests/scalars/test_scalars.py @@ -25,7 +25,7 @@ PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, - np_1darray, + np_1darray_bool, np_2darray, np_ndarray, np_ndarray_bool, @@ -40,7 +40,7 @@ ) if not PD_LTE_23: - from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip + from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip else: Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] @@ -318,55 +318,55 @@ def test_interval_cmp() -> None: interval_index_int = pd.IntervalIndex([interval_i]) check( - assert_type(interval_index_int >= interval_i, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_index_int >= interval_i, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_index_int < interval_i, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_index_int < interval_i, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_index_int <= interval_i, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_index_int <= interval_i, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_index_int > interval_i, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_index_int > interval_i, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_i >= interval_index_int, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_i >= interval_index_int, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_i < interval_index_int, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_i < interval_index_int, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_i <= interval_index_int, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_i <= interval_index_int, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_i > interval_index_int, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_i > interval_index_int, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_index_int == interval_i, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_index_int == interval_i, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_index_int != interval_i, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_index_int != interval_i, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_i == interval_index_int, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_i == interval_index_int, np_1darray_bool), + np_1darray_bool, ) check( - assert_type(interval_i != interval_index_int, np_1darray[np.bool]), - np_1darray[np.bool], + assert_type(interval_i != interval_index_int, np_1darray_bool), + np_1darray_bool, ) @@ -817,29 +817,29 @@ def test_timedelta_cmp_index() -> None: td_idx = pd.to_timedelta([1, 2, 3], unit="D") # TimedeltaIndex # >, <= - gt1 = check(assert_type(td > td_idx, np_1darray[np.bool]), np_1darray[np.bool]) - le1 = check(assert_type(td <= td_idx, np_1darray[np.bool]), np_1darray[np.bool]) + gt1 = check(assert_type(td > td_idx, np_1darray_bool), np_1darray_bool) + le1 = check(assert_type(td <= td_idx, np_1darray_bool), np_1darray_bool) assert (gt1 != le1).all() - gt2 = check(assert_type(td_idx > td, np_1darray[np.bool]), np_1darray[np.bool]) - le2 = check(assert_type(td_idx <= td, np_1darray[np.bool]), np_1darray[np.bool]) + gt2 = check(assert_type(td_idx > td, np_1darray_bool), np_1darray_bool) + le2 = check(assert_type(td_idx <= td, np_1darray_bool), np_1darray_bool) assert (gt2 != le2).all() # <, >= - lt1 = check(assert_type(td < td_idx, np_1darray[np.bool]), np_1darray[np.bool]) - ge1 = check(assert_type(td >= td_idx, np_1darray[np.bool]), np_1darray[np.bool]) + lt1 = check(assert_type(td < td_idx, np_1darray_bool), np_1darray_bool) + ge1 = check(assert_type(td >= td_idx, np_1darray_bool), np_1darray_bool) assert (lt1 != ge1).all() - lt2 = check(assert_type(td_idx < td, np_1darray[np.bool]), np_1darray[np.bool]) - ge2 = check(assert_type(td_idx >= td, np_1darray[np.bool]), np_1darray[np.bool]) + lt2 = check(assert_type(td_idx < td, np_1darray_bool), np_1darray_bool) + ge2 = check(assert_type(td_idx >= td, np_1darray_bool), np_1darray_bool) assert (lt2 != ge2).all() # ==, != - eq1 = check(assert_type(td == td_idx, np_1darray[np.bool]), np_1darray[np.bool]) - ne1 = check(assert_type(td != td_idx, np_1darray[np.bool]), np_1darray[np.bool]) + eq1 = check(assert_type(td == td_idx, np_1darray_bool), np_1darray_bool) + ne1 = check(assert_type(td != td_idx, np_1darray_bool), np_1darray_bool) assert (eq1 != ne1).all() # ==, != (td on the rhs, use == and != of lhs) - eq_rhs1 = check(assert_type(td_idx == td, np_1darray[np.bool]), np_1darray[np.bool]) - ne_rhs1 = check(assert_type(td_idx != td, np_1darray[np.bool]), np_1darray[np.bool]) + eq_rhs1 = check(assert_type(td_idx == td, np_1darray_bool), np_1darray_bool) + ne_rhs1 = check(assert_type(td_idx != td, np_1darray_bool), np_1darray_bool) assert (eq_rhs1 != ne_rhs1).all() @@ -862,11 +862,11 @@ def test_timedelta_cmp_array() -> None: gt_2d2 = check(assert_type(arr_2d > td, np_2darray[np.bool]), np_2darray[np.bool]) le_2d2 = check(assert_type(arr_2d <= td, np_2darray[np.bool]), np_2darray[np.bool]) assert (gt_2d2 != le_2d2).all() - gt_1d1 = check(assert_type(td > arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) - le_1d1 = check(assert_type(td <= arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) + gt_1d1 = check(assert_type(td > arr_1d, np_1darray_bool), np_1darray_bool) + le_1d1 = check(assert_type(td <= arr_1d, np_1darray_bool), np_1darray_bool) assert (gt_1d1 != le_1d1).all() - gt_1d2 = check(assert_type(arr_1d > td, np_1darray[np.bool]), np_1darray[np.bool]) - le_1d2 = check(assert_type(arr_1d <= td, np_1darray[np.bool]), np_1darray[np.bool]) + gt_1d2 = check(assert_type(arr_1d > td, np_1darray_bool), np_1darray_bool) + le_1d2 = check(assert_type(arr_1d <= td, np_1darray_bool), np_1darray_bool) assert (gt_1d2 != le_1d2).all() # <, >= @@ -882,11 +882,11 @@ def test_timedelta_cmp_array() -> None: lt_2d2 = check(assert_type(arr_2d < td, np_2darray[np.bool]), np_2darray[np.bool]) ge_2d2 = check(assert_type(arr_2d >= td, np_2darray[np.bool]), np_2darray[np.bool]) assert (lt_2d2 != ge_2d2).all() - lt_1d1 = check(assert_type(td < arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) - ge_1d1 = check(assert_type(td >= arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) + lt_1d1 = check(assert_type(td < arr_1d, np_1darray_bool), np_1darray_bool) + ge_1d1 = check(assert_type(td >= arr_1d, np_1darray_bool), np_1darray_bool) assert (lt_1d1 != ge_1d1).all() - lt_1d2 = check(assert_type(arr_1d < td, np_1darray[np.bool]), np_1darray[np.bool]) - ge_1d2 = check(assert_type(arr_1d >= td, np_1darray[np.bool]), np_1darray[np.bool]) + lt_1d2 = check(assert_type(arr_1d < td, np_1darray_bool), np_1darray_bool) + ge_1d2 = check(assert_type(arr_1d >= td, np_1darray_bool), np_1darray_bool) assert (lt_1d2 != ge_1d2).all() # ==, != @@ -896,8 +896,8 @@ def test_timedelta_cmp_array() -> None: eq_2d1 = check(assert_type(td == arr_2d, np_2darray[np.bool]), np_2darray[np.bool]) ne_2d1 = check(assert_type(td != arr_2d, np_2darray[np.bool]), np_2darray[np.bool]) assert (eq_2d1 != ne_2d1).all() - eq_1d1 = check(assert_type(td == arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) - ne_1d1 = check(assert_type(td != arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) + eq_1d1 = check(assert_type(td == arr_1d, np_1darray_bool), np_1darray_bool) + ne_1d1 = check(assert_type(td != arr_1d, np_1darray_bool), np_1darray_bool) assert (eq_1d1 != ne_1d1).all() # ==, != (td on the rhs, use == and != of lhs) @@ -907,8 +907,8 @@ def test_timedelta_cmp_array() -> None: eq_rhs_2d1 = check(assert_type(arr_2d == td, Any), np_2darray[np.bool]) ne_rhs_2d1 = check(assert_type(arr_2d != td, Any), np_2darray[np.bool]) assert (eq_rhs_2d1 != ne_rhs_2d1).all() - eq_rhs_1d1 = check(assert_type(arr_1d == td, Any), np_1darray[np.bool]) - ne_rhs_1d1 = check(assert_type(arr_1d != td, Any), np_1darray[np.bool]) + eq_rhs_1d1 = check(assert_type(arr_1d == td, Any), np_1darray_bool) + ne_rhs_1d1 = check(assert_type(arr_1d != td, Any), np_1darray_bool) assert (eq_rhs_1d1 != ne_rhs_1d1).all() @@ -1186,56 +1186,48 @@ def test_timestamp_cmp_index() -> None: un_idx = pd.DataFrame({"a": [1]}, index=dt_idx).index # >, <= - gt_dt1 = check(assert_type(ts > dt_idx, np_1darray[np.bool]), np_1darray[np.bool]) - le_dt1 = check(assert_type(ts <= dt_idx, np_1darray[np.bool]), np_1darray[np.bool]) + gt_dt1 = check(assert_type(ts > dt_idx, np_1darray_bool), np_1darray_bool) + le_dt1 = check(assert_type(ts <= dt_idx, np_1darray_bool), np_1darray_bool) assert (gt_dt1 != le_dt1).all() - gt_dt2 = check(assert_type(dt_idx > ts, np_1darray[np.bool]), np_1darray[np.bool]) - le_dt2 = check(assert_type(dt_idx <= ts, np_1darray[np.bool]), np_1darray[np.bool]) + gt_dt2 = check(assert_type(dt_idx > ts, np_1darray_bool), np_1darray_bool) + le_dt2 = check(assert_type(dt_idx <= ts, np_1darray_bool), np_1darray_bool) assert (gt_dt2 != le_dt2).all() - gt_un1 = check(assert_type(ts > un_idx, np_1darray[np.bool]), np_1darray[np.bool]) - le_un1 = check(assert_type(ts <= un_idx, np_1darray[np.bool]), np_1darray[np.bool]) + gt_un1 = check(assert_type(ts > un_idx, np_1darray_bool), np_1darray_bool) + le_un1 = check(assert_type(ts <= un_idx, np_1darray_bool), np_1darray_bool) assert (gt_un1 != le_un1).all() - gt_un2 = check(assert_type(un_idx > ts, np_1darray[np.bool]), np_1darray[np.bool]) - le_un2 = check(assert_type(un_idx <= ts, np_1darray[np.bool]), np_1darray[np.bool]) + gt_un2 = check(assert_type(un_idx > ts, np_1darray_bool), np_1darray_bool) + le_un2 = check(assert_type(un_idx <= ts, np_1darray_bool), np_1darray_bool) assert (gt_un2 != le_un2).all() # <, >= - lt_dt1 = check(assert_type(ts < dt_idx, np_1darray[np.bool]), np_1darray[np.bool]) - ge_dt1 = check(assert_type(ts >= dt_idx, np_1darray[np.bool]), np_1darray[np.bool]) + lt_dt1 = check(assert_type(ts < dt_idx, np_1darray_bool), np_1darray_bool) + ge_dt1 = check(assert_type(ts >= dt_idx, np_1darray_bool), np_1darray_bool) assert (lt_dt1 != ge_dt1).all() - lt_dt2 = check(assert_type(dt_idx < ts, np_1darray[np.bool]), np_1darray[np.bool]) - ge_dt2 = check(assert_type(dt_idx >= ts, np_1darray[np.bool]), np_1darray[np.bool]) + lt_dt2 = check(assert_type(dt_idx < ts, np_1darray_bool), np_1darray_bool) + ge_dt2 = check(assert_type(dt_idx >= ts, np_1darray_bool), np_1darray_bool) assert (lt_dt2 != ge_dt2).all() - lt_un1 = check(assert_type(ts < un_idx, np_1darray[np.bool]), np_1darray[np.bool]) - ge_un1 = check(assert_type(ts >= un_idx, np_1darray[np.bool]), np_1darray[np.bool]) + lt_un1 = check(assert_type(ts < un_idx, np_1darray_bool), np_1darray_bool) + ge_un1 = check(assert_type(ts >= un_idx, np_1darray_bool), np_1darray_bool) assert (lt_un1 != ge_un1).all() - lt_un2 = check(assert_type(un_idx < ts, np_1darray[np.bool]), np_1darray[np.bool]) - ge_un2 = check(assert_type(un_idx >= ts, np_1darray[np.bool]), np_1darray[np.bool]) + lt_un2 = check(assert_type(un_idx < ts, np_1darray_bool), np_1darray_bool) + ge_un2 = check(assert_type(un_idx >= ts, np_1darray_bool), np_1darray_bool) assert (lt_un2 != ge_un2).all() # ==, != - eq_dt1 = check(assert_type(ts == dt_idx, np_1darray[np.bool]), np_1darray[np.bool]) - ne_dt1 = check(assert_type(ts != dt_idx, np_1darray[np.bool]), np_1darray[np.bool]) + eq_dt1 = check(assert_type(ts == dt_idx, np_1darray_bool), np_1darray_bool) + ne_dt1 = check(assert_type(ts != dt_idx, np_1darray_bool), np_1darray_bool) assert (eq_dt1 != ne_dt1).all() # there is a mypy bug where ts.__eq__(Index) gets revealed as Any and not np_1darray - eq_un1 = check(assert_type(ts == un_idx, np_1darray[np.bool]), np_1darray[np.bool]) # type: ignore[assert-type] - ne_un1 = check(assert_type(ts != un_idx, np_1darray[np.bool]), np_1darray[np.bool]) # type: ignore[assert-type] + eq_un1 = check(assert_type(ts == un_idx, np_1darray_bool), np_1darray_bool) # type: ignore[assert-type] + ne_un1 = check(assert_type(ts != un_idx, np_1darray_bool), np_1darray_bool) # type: ignore[assert-type] assert (eq_un1 != ne_un1).all() # ==, != (ts on the rhs, use == and != of lhs) - eq_rhs_dt1 = check( - assert_type(dt_idx == ts, np_1darray[np.bool]), np_1darray[np.bool] - ) - ne_rhs_dt1 = check( - assert_type(dt_idx != ts, np_1darray[np.bool]), np_1darray[np.bool] - ) + eq_rhs_dt1 = check(assert_type(dt_idx == ts, np_1darray_bool), np_1darray_bool) + ne_rhs_dt1 = check(assert_type(dt_idx != ts, np_1darray_bool), np_1darray_bool) assert (eq_rhs_dt1 != ne_rhs_dt1).all() - eq_rhs_un1 = check( - assert_type(un_idx == ts, np_1darray[np.bool]), np_1darray[np.bool] - ) - ne_rhs_un1 = check( - assert_type(un_idx != ts, np_1darray[np.bool]), np_1darray[np.bool] - ) + eq_rhs_un1 = check(assert_type(un_idx == ts, np_1darray_bool), np_1darray_bool) + ne_rhs_un1 = check(assert_type(un_idx != ts, np_1darray_bool), np_1darray_bool) assert (eq_rhs_un1 != ne_rhs_un1).all() @@ -1258,11 +1250,11 @@ def test_timestamp_cmp_array() -> None: gt_2d2 = check(assert_type(arr_2d > ts, np_2darray[np.bool]), np_2darray[np.bool]) le_2d2 = check(assert_type(arr_2d <= ts, np_2darray[np.bool]), np_2darray[np.bool]) assert (gt_2d2 != le_2d2).all() - gt_1d1 = check(assert_type(ts > arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) - le_1d1 = check(assert_type(ts <= arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) + gt_1d1 = check(assert_type(ts > arr_1d, np_1darray_bool), np_1darray_bool) + le_1d1 = check(assert_type(ts <= arr_1d, np_1darray_bool), np_1darray_bool) assert (gt_1d1 != le_1d1).all() - gt_1d2 = check(assert_type(arr_1d > ts, np_1darray[np.bool]), np_1darray[np.bool]) - le_1d2 = check(assert_type(arr_1d <= ts, np_1darray[np.bool]), np_1darray[np.bool]) + gt_1d2 = check(assert_type(arr_1d > ts, np_1darray_bool), np_1darray_bool) + le_1d2 = check(assert_type(arr_1d <= ts, np_1darray_bool), np_1darray_bool) assert (gt_1d2 != le_1d2).all() # <, >= @@ -1278,11 +1270,11 @@ def test_timestamp_cmp_array() -> None: lt_2d2 = check(assert_type(arr_2d < ts, np_2darray[np.bool]), np_2darray[np.bool]) ge_2d2 = check(assert_type(arr_2d >= ts, np_2darray[np.bool]), np_2darray[np.bool]) assert (lt_2d2 != ge_2d2).all() - lt_1d1 = check(assert_type(ts < arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) - ge_1d1 = check(assert_type(ts >= arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) + lt_1d1 = check(assert_type(ts < arr_1d, np_1darray_bool), np_1darray_bool) + ge_1d1 = check(assert_type(ts >= arr_1d, np_1darray_bool), np_1darray_bool) assert (lt_1d1 != ge_1d1).all() - lt_1d2 = check(assert_type(arr_1d < ts, np_1darray[np.bool]), np_1darray[np.bool]) - ge_1d2 = check(assert_type(arr_1d >= ts, np_1darray[np.bool]), np_1darray[np.bool]) + lt_1d2 = check(assert_type(arr_1d < ts, np_1darray_bool), np_1darray_bool) + ge_1d2 = check(assert_type(arr_1d >= ts, np_1darray_bool), np_1darray_bool) assert (lt_1d2 != ge_1d2).all() # ==, != @@ -1292,8 +1284,8 @@ def test_timestamp_cmp_array() -> None: eq_2d1 = check(assert_type(ts == arr_2d, np_2darray[np.bool]), np_2darray[np.bool]) ne_2d1 = check(assert_type(ts != arr_2d, np_2darray[np.bool]), np_2darray[np.bool]) assert (eq_2d1 != ne_2d1).all() - eq_1d1 = check(assert_type(ts == arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) - ne_1d1 = check(assert_type(ts != arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) + eq_1d1 = check(assert_type(ts == arr_1d, np_1darray_bool), np_1darray_bool) + ne_1d1 = check(assert_type(ts != arr_1d, np_1darray_bool), np_1darray_bool) assert (eq_1d1 != ne_1d1).all() # ==, != (td on the rhs, use == and != of lhs) @@ -1303,8 +1295,8 @@ def test_timestamp_cmp_array() -> None: eq_rhs_2d1 = check(assert_type(arr_2d == ts, Any), np_2darray[np.bool]) ne_rhs_2d1 = check(assert_type(arr_2d != ts, Any), np_2darray[np.bool]) assert (eq_rhs_2d1 != ne_rhs_2d1).all() - eq_rhs_1d1 = check(assert_type(arr_1d == ts, Any), np_1darray[np.bool]) - ne_rhs_1d1 = check(assert_type(arr_1d != ts, Any), np_1darray[np.bool]) + eq_rhs_1d1 = check(assert_type(arr_1d == ts, Any), np_1darray_bool) + ne_rhs_1d1 = check(assert_type(arr_1d != ts, Any), np_1darray_bool) assert (eq_rhs_1d1 != ne_rhs_1d1).all() @@ -1817,29 +1809,29 @@ def test_period_cmp_index() -> None: p_idx = pd.period_range("2012-1-1", periods=10, freq="D") # >, <= - gt1 = check(assert_type(p > p_idx, np_1darray[np.bool]), np_1darray[np.bool]) - le1 = check(assert_type(p <= p_idx, np_1darray[np.bool]), np_1darray[np.bool]) + gt1 = check(assert_type(p > p_idx, np_1darray_bool), np_1darray_bool) + le1 = check(assert_type(p <= p_idx, np_1darray_bool), np_1darray_bool) assert (gt1 != le1).all() - gt2 = check(assert_type(p_idx > p, np_1darray[np.bool]), np_1darray[np.bool]) - le2 = check(assert_type(p_idx <= p, np_1darray[np.bool]), np_1darray[np.bool]) + gt2 = check(assert_type(p_idx > p, np_1darray_bool), np_1darray_bool) + le2 = check(assert_type(p_idx <= p, np_1darray_bool), np_1darray_bool) assert (gt2 != le2).all() # <, >= - lt1 = check(assert_type(p < p_idx, np_1darray[np.bool]), np_1darray[np.bool]) - ge1 = check(assert_type(p >= p_idx, np_1darray[np.bool]), np_1darray[np.bool]) + lt1 = check(assert_type(p < p_idx, np_1darray_bool), np_1darray_bool) + ge1 = check(assert_type(p >= p_idx, np_1darray_bool), np_1darray_bool) assert (lt1 != ge1).all() - lt2 = check(assert_type(p_idx < p, np_1darray[np.bool]), np_1darray[np.bool]) - ge2 = check(assert_type(p_idx >= p, np_1darray[np.bool]), np_1darray[np.bool]) + lt2 = check(assert_type(p_idx < p, np_1darray_bool), np_1darray_bool) + ge2 = check(assert_type(p_idx >= p, np_1darray_bool), np_1darray_bool) assert (lt2 != ge2).all() # ==, != - eq1 = check(assert_type(p == p_idx, np_1darray[np.bool]), np_1darray[np.bool]) - ne1 = check(assert_type(p != p_idx, np_1darray[np.bool]), np_1darray[np.bool]) + eq1 = check(assert_type(p == p_idx, np_1darray_bool), np_1darray_bool) + ne1 = check(assert_type(p != p_idx, np_1darray_bool), np_1darray_bool) assert (eq1 != ne1).all() # ==, != (p on the rhs, use == and != of lhs) - eq_rhs1 = check(assert_type(p_idx == p, np_1darray[np.bool]), np_1darray[np.bool]) - ne_rhs1 = check(assert_type(p_idx != p, np_1darray[np.bool]), np_1darray[np.bool]) + eq_rhs1 = check(assert_type(p_idx == p, np_1darray_bool), np_1darray_bool) + ne_rhs1 = check(assert_type(p_idx != p, np_1darray_bool), np_1darray_bool) assert (eq_rhs1 != ne_rhs1).all() @@ -1856,8 +1848,8 @@ def test_period_cmp_array() -> None: gt_2d1 = check(assert_type(p > arr_2d, np_2darray[np.bool]), np_2darray[np.bool]) le_2d1 = check(assert_type(p <= arr_2d, np_2darray[np.bool]), np_2darray[np.bool]) assert (gt_2d1 != le_2d1).all() - gt_1d1 = check(assert_type(p > arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) - le_1d1 = check(assert_type(p <= arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) + gt_1d1 = check(assert_type(p > arr_1d, np_1darray_bool), np_1darray_bool) + le_1d1 = check(assert_type(p <= arr_1d, np_1darray_bool), np_1darray_bool) assert (gt_1d1 != le_1d1).all() # p on the rhs, type depends on np.ndarray > and <= methods gt_nd2 = check(assert_type(arr_nd > p, np_ndarray_bool), np_ndarray_bool, np.bool) @@ -1866,8 +1858,8 @@ def test_period_cmp_array() -> None: gt_2d2 = check(assert_type(arr_2d > p, np_ndarray_bool), np_2darray[np.bool]) le_2d2 = check(assert_type(arr_2d <= p, np_ndarray_bool), np_2darray[np.bool]) assert (gt_2d2 != le_2d2).all() - gt_1d2 = check(assert_type(arr_1d > p, np_ndarray_bool), np_1darray[np.bool]) - le_1d2 = check(assert_type(arr_1d <= p, np_ndarray_bool), np_1darray[np.bool]) + gt_1d2 = check(assert_type(arr_1d > p, np_ndarray_bool), np_1darray_bool) + le_1d2 = check(assert_type(arr_1d <= p, np_ndarray_bool), np_1darray_bool) assert (gt_1d2 != le_1d2).all() # <, >= @@ -1877,8 +1869,8 @@ def test_period_cmp_array() -> None: lt_2d1 = check(assert_type(p < arr_2d, np_2darray[np.bool]), np_2darray[np.bool]) ge_2d1 = check(assert_type(p >= arr_2d, np_2darray[np.bool]), np_2darray[np.bool]) assert (lt_2d1 != ge_2d1).all() - lt_1d1 = check(assert_type(p < arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) - ge_1d1 = check(assert_type(p >= arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) + lt_1d1 = check(assert_type(p < arr_1d, np_1darray_bool), np_1darray_bool) + ge_1d1 = check(assert_type(p >= arr_1d, np_1darray_bool), np_1darray_bool) assert (lt_1d1 != ge_1d1).all() # p on the rhs, type depends on np.ndarray < and >= methods lt_nd2 = check(assert_type(arr_nd < p, np_ndarray_bool), np_ndarray_bool, np.bool) @@ -1887,8 +1879,8 @@ def test_period_cmp_array() -> None: lt_2d2 = check(assert_type(arr_2d < p, np_ndarray_bool), np_2darray[np.bool]) ge_2d2 = check(assert_type(arr_2d >= p, np_ndarray_bool), np_2darray[np.bool]) assert (lt_2d2 != ge_2d2).all() - lt_1d2 = check(assert_type(arr_1d < p, np_ndarray_bool), np_1darray[np.bool]) - ge_1d2 = check(assert_type(arr_1d >= p, np_ndarray_bool), np_1darray[np.bool]) + lt_1d2 = check(assert_type(arr_1d < p, np_ndarray_bool), np_1darray_bool) + ge_1d2 = check(assert_type(arr_1d >= p, np_ndarray_bool), np_1darray_bool) assert (lt_1d2 != ge_1d2).all() # ==, != @@ -1898,8 +1890,8 @@ def test_period_cmp_array() -> None: eq_2d1 = check(assert_type(p == arr_2d, np_2darray[np.bool]), np_2darray[np.bool]) ne_2d1 = check(assert_type(p != arr_2d, np_2darray[np.bool]), np_2darray[np.bool]) assert (eq_2d1 != ne_2d1).all() - eq_1d1 = check(assert_type(p == arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) - ne_1d1 = check(assert_type(p != arr_1d, np_1darray[np.bool]), np_1darray[np.bool]) + eq_1d1 = check(assert_type(p == arr_1d, np_1darray_bool), np_1darray_bool) + ne_1d1 = check(assert_type(p != arr_1d, np_1darray_bool), np_1darray_bool) assert (eq_1d1 != ne_1d1).all() # ==, != (td on the rhs, use == and != of lhs) @@ -1909,8 +1901,8 @@ def test_period_cmp_array() -> None: eq_rhs_2d1 = check(assert_type(arr_2d == p, Any), np_2darray[np.bool]) ne_rhs_2d1 = check(assert_type(arr_2d != p, Any), np_2darray[np.bool]) assert (eq_rhs_2d1 != ne_rhs_2d1).all() - eq_rhs_1d1 = check(assert_type(arr_1d == p, Any), np_1darray[np.bool]) - ne_rhs_1d1 = check(assert_type(arr_1d != p, Any), np_1darray[np.bool]) + eq_rhs_1d1 = check(assert_type(arr_1d == p, Any), np_1darray_bool) + ne_rhs_1d1 = check(assert_type(arr_1d != p, Any), np_1darray_bool) assert (eq_rhs_1d1 != ne_rhs_1d1).all() diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 4e412133e..5152ff528 100644 --- a/tests/series/test_series.py +++ b/tests/series/test_series.py @@ -34,7 +34,6 @@ ) from pandas.api.typing import NAType from pandas.core.arrays.datetimes import DatetimeArray -from pandas.core.arrays.string_ import StringArray from pandas.core.arrays.timedeltas import TimedeltaArray from pandas.core.window import ExponentialMovingWindow from pandas.core.window.expanding import Expanding @@ -103,7 +102,7 @@ ) if not PD_LTE_23: - from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip + from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip else: Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] @@ -1424,23 +1423,17 @@ def test_types_rename_axis() -> None: def test_types_values() -> None: check( assert_type( - pd.Series([1, 2, 3]).values, - np_1darray | ExtensionArray | pd.Categorical, + pd.Series([1, 2, 3]).values, np_1darray | ExtensionArray | pd.Categorical ), np_1darray, np.integer, ) - valresult_type: type[np_1darray | ExtensionArray | pd.Categorical] - if PD_LTE_23: - valresult_type = np_1darray - else: - valresult_type = StringArray check( assert_type( - pd.Series(list("aabc")).values, - np_1darray | ExtensionArray | pd.Categorical, + pd.Series(list("aabc")).values, np_1darray | ExtensionArray | pd.Categorical ), - valresult_type, + # TODO: BaseStringArray after pandas-dev/pandas-stubs#1469 + np_1darray if PD_LTE_23 else ExtensionArray, str, ) check( @@ -2003,20 +1996,18 @@ def test_dtype_type() -> None: def test_types_to_numpy() -> None: s = pd.Series(["a", "b", "c"], dtype=str) - check(assert_type(s.to_numpy(), np_1darray[np.str_]), np_1darray) + check(assert_type(s.to_numpy(), np_1darray_str), np_1darray_str) check( - assert_type(s.to_numpy(dtype="str", copy=True), np_1darray[np.str_]), np_1darray + assert_type(s.to_numpy(dtype="str", copy=True), np_1darray_str), np_1darray_str ) - check(assert_type(s.to_numpy(na_value=0), np_1darray[np.str_]), np_1darray) + check(assert_type(s.to_numpy(na_value=0), np_1darray_str), np_1darray_str) + check(assert_type(s.to_numpy(na_value=np.int32(4)), np_1darray_str), np_1darray_str) check( - assert_type(s.to_numpy(na_value=np.int32(4)), np_1darray[np.str_]), np_1darray + assert_type(s.to_numpy(na_value=np.float16(4)), np_1darray_str), np_1darray_str ) check( - assert_type(s.to_numpy(na_value=np.float16(4)), np_1darray[np.str_]), np_1darray - ) - check( - assert_type(s.to_numpy(na_value=np.complex128(4, 7)), np_1darray[np.str_]), - np_1darray, + assert_type(s.to_numpy(na_value=np.complex128(4, 7)), np_1darray_str), + np_1darray_str, ) check(assert_type(pd.Series().to_numpy(), np_1darray), np_1darray) @@ -2025,7 +2016,7 @@ def test_types_to_numpy() -> None: def test_to_numpy() -> None: """Test Series.to_numpy for different types.""" s_str = pd.Series(["a", "b", "c"], dtype=str) - check(assert_type(s_str.to_numpy(), np_1darray_str), np_1darray, str) + check(assert_type(s_str.to_numpy(), np_1darray_str), np_1darray_str) s_bytes = pd.Series(["a", "b", "c"]).astype(bytes) check(assert_type(s_bytes.to_numpy(), np_1darray_bytes), np_1darray, np.bytes_) @@ -3222,6 +3213,21 @@ def test_to_json_mode() -> None: _result3 = s.to_json(orient="records", lines=False, mode="a") # type: ignore[call-overload] # pyright: ignore[reportArgumentType,reportCallIssue] +def test_interpolate() -> None: + s = pd.Series(range(3)) + check( + assert_type(s.interpolate(method="linear"), "pd.Series[int]"), + pd.Series, + np.integer, + ) + check( + assert_type(s.interpolate(method="linear", inplace=False), "pd.Series[int]"), + pd.Series, + np.integer, + ) + check(assert_type(s.interpolate(method="linear", inplace=True), None), type(None)) + + def test_groupby_diff() -> None: # GH 658 s = pd.Series([1.0, 2.0, 3.0, np.nan]) diff --git a/tests/test_frame.py b/tests/test_frame.py index eb2960b0f..9c03fcd66 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -79,7 +79,7 @@ _PandasNamedTuple: TypeAlias = tuple if not PD_LTE_23: - from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip + from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip else: Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] @@ -590,10 +590,15 @@ def test_types_set_index() -> None: check(assert_type(df.set_index("col1"), pd.DataFrame), pd.DataFrame) check(assert_type(df.set_index("col1", drop=False), pd.DataFrame), pd.DataFrame) check(assert_type(df.set_index("col1", append=True), pd.DataFrame), pd.DataFrame) - check( - assert_type(df.set_index("col1", verify_integrity=True), pd.DataFrame), - pd.DataFrame, - ) + with pytest_warns_bounded( + Pandas4Warning, + "The 'verify_integrity' keyword in DataFrame.set_index is deprecated and will be removed in a future version. Directly check the result.index.is_unique instead.", + lower="2.99", + ): + check( + assert_type(df.set_index("col1", verify_integrity=True), pd.DataFrame), + pd.DataFrame, + ) check(assert_type(df.set_index(["col1", "col2"]), pd.DataFrame), pd.DataFrame) check(assert_type(df.set_index("col1", inplace=True), None), type(None)) # GH 140 @@ -967,10 +972,7 @@ def test_dataframe_clip() -> None: assert_type(df.clip(upper=None, axis="index", inplace=True), pd.DataFrame), pd.DataFrame, ) - check( - assert_type(df.clip(upper=15, axis="index", inplace=True), None), - type(None), - ) + check(assert_type(df.clip(upper=15, axis="index", inplace=True), None), type(None)) check( assert_type(df.clip(upper=pd.Series([1, 2]), axis="index", inplace=True), None), type(None), @@ -3752,10 +3754,7 @@ def test_to_records() -> None: np.recarray, ) dtypes = {"col1": np.int8, "col2": np.int16} - check( - assert_type(DF.to_records(False, dtypes), np.recarray), - np.recarray, - ) + check(assert_type(DF.to_records(False, dtypes), np.recarray), np.recarray) def test_to_dict_simple() -> None: @@ -3776,13 +3775,28 @@ def test_to_dict_simple() -> None: def test(mapping: Mapping) -> None: # pyright: ignore[reportUnusedFunction] data.to_dict(into=mapping) # type: ignore[call-overload] # pyright: ignore[reportArgumentType,reportCallIssue] + def _1() -> None: # pyright: ignore[reportUnusedFunction] assert_type(data.to_dict(into=defaultdict), Never) + + def _2() -> None: # pyright: ignore[reportUnusedFunction] assert_type(data.to_dict("records", into=defaultdict), Never) + + def _3() -> None: # pyright: ignore[reportUnusedFunction] assert_type(data.to_dict("index", into=defaultdict), Never) + + def _4() -> None: # pyright: ignore[reportUnusedFunction] assert_type(data.to_dict("dict", into=defaultdict), Never) + + def _5() -> None: # pyright: ignore[reportUnusedFunction] assert_type(data.to_dict("list", into=defaultdict), Never) + + def _6() -> None: # pyright: ignore[reportUnusedFunction] assert_type(data.to_dict("series", into=defaultdict), Never) + + def _7() -> None: # pyright: ignore[reportUnusedFunction] assert_type(data.to_dict("split", into=defaultdict), Never) + + def _8() -> None: # pyright: ignore[reportUnusedFunction] assert_type(data.to_dict("tight", into=defaultdict), Never) @@ -4330,10 +4344,10 @@ def test_to_dict_index() -> None: assert_type(df.to_dict(orient="split", index=False), dict[str, list]), dict, str ) if TYPE_CHECKING_INVALID_USAGE: - check(assert_type(df.to_dict(orient="records", index=False), list[dict[Hashable, Any]]), list) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] - check(assert_type(df.to_dict(orient="dict", index=False), dict[Hashable, Any]), dict) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] - check(assert_type(df.to_dict(orient="series", index=False), dict[Hashable, Any]), dict) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] - check(assert_type(df.to_dict(orient="index", index=False), dict[Hashable, Any]), dict) # type: ignore[assert-type, call-overload] # pyright: ignore[reportArgumentType,reportAssertTypeFailure,reportCallIssue] + _0 = df.to_dict(orient="records", index=False) # type: ignore[call-overload] # pyright: ignore[reportArgumentType,reportCallIssue] + _1 = df.to_dict(orient="dict", index=False) # type: ignore[call-overload] # pyright: ignore[reportArgumentType,reportCallIssue] + _2 = df.to_dict(orient="series", index=False) # type: ignore[call-overload] # pyright: ignore[reportArgumentType,reportCallIssue] + _3 = df.to_dict(orient="index", index=False) # type: ignore[call-overload] # pyright: ignore[reportArgumentType,reportCallIssue] def test_suffix_prefix_index() -> None: @@ -4396,13 +4410,22 @@ def test_select_dtypes() -> None: ), pd.DataFrame, ) - if TYPE_CHECKING_INVALID_USAGE: - # include and exclude shall not be both empty + + # include and exclude shall not be both empty + def _0() -> None: # pyright: ignore[reportUnusedFunction] assert_never(df.select_dtypes([], [])) - assert_never(df.select_dtypes()) - # str like dtypes are not allowed + + if TYPE_CHECKING_INVALID_USAGE: + _1 = df.select_dtypes() # type: ignore[call-overload] # pyright: ignore[reportCallIssue] + + # str like dtypes are not allowed + def _2() -> None: # pyright: ignore[reportUnusedFunction] assert_never(df.select_dtypes(str)) + + def _3() -> None: # pyright: ignore[reportUnusedFunction] assert_never(df.select_dtypes(exclude=str)) + + def _4() -> None: # pyright: ignore[reportUnusedFunction] assert_never(df.select_dtypes(None, str)) @@ -4424,7 +4447,7 @@ def test_to_json_mode() -> None: _result3 = df.to_json(orient="records", lines=False, mode="a") # type: ignore[call-overload] # pyright: ignore[reportArgumentType,reportCallIssue] -def test_interpolate_inplace() -> None: +def test_interpolate() -> None: # GH 691 df = pd.DataFrame({"a": range(3)}) check(assert_type(df.interpolate(method="linear"), pd.DataFrame), pd.DataFrame) @@ -4437,7 +4460,9 @@ def test_interpolate_inplace() -> None: def test_getitem_generator() -> None: # GH 685 - check(assert_type(DF[(f"col{i+1}" for i in range(2))], pd.DataFrame), pd.DataFrame) + check( + assert_type(DF[(f"col{i + 1}" for i in range(2))], pd.DataFrame), pd.DataFrame + ) def test_getitem_dict_keys() -> None: @@ -4589,7 +4614,6 @@ def test_hashable_args() -> None: test = ["test"] with ensure_clean() as path: - df.to_stata(path, version=117, convert_strl=test) df.to_stata(path, version=117, convert_strl=["test"]) @@ -4714,7 +4738,6 @@ def test_unstack() -> None: def test_from_records() -> None: - # test with np.ndarray arr = np.array([[1, "a"], [2, "b"]], dtype=object).reshape(2, 2) check(assert_type(pd.DataFrame.from_records(arr), pd.DataFrame), pd.DataFrame) diff --git a/tests/test_groupby.py b/tests/test_groupby.py index a6f623ab3..b0287217b 100644 --- a/tests/test_groupby.py +++ b/tests/test_groupby.py @@ -259,35 +259,24 @@ def df2scalar(val: DataFrame) -> float: ), DataFrame, ) - check( - assert_type(GB_DF.resample("ME").interpolate(inplace=True), None), - type(None), - ) - else: - def resample_interpolate(x: DataFrame) -> DataFrame: - return x.resample("ME").interpolate() + def resample_interpolate(x: DataFrame) -> DataFrame: + return x.resample("ME").interpolate() - check( - assert_type( - GB_DF.apply(resample_interpolate), - DataFrame, - ), - DataFrame, - ) + check(assert_type(GB_DF.apply(resample_interpolate), DataFrame), DataFrame) - def resample_interpolate_linear(x: DataFrame) -> DataFrame: - return x.resample("ME").interpolate(method="linear") + def resample_interpolate_linear(x: DataFrame) -> DataFrame: + return x.resample("ME").interpolate(method="linear") - check( - assert_type( - GB_DF.apply( - resample_interpolate_linear, - ), - DataFrame, + check( + assert_type( + GB_DF.apply( + resample_interpolate_linear, ), DataFrame, - ) + ), + DataFrame, + ) # pipe def g(val: Resampler[DataFrame]) -> DataFrame: @@ -427,9 +416,6 @@ def f(val: Series) -> float: Series, float, ) - check( - assert_type(GB_S.resample("ME").interpolate(inplace=True), None), type(None) - ) else: check( assert_type( @@ -438,14 +424,6 @@ def f(val: Series) -> float: Series, float, ) - # This fails typing checks, and should work in 3.0, but is a bug in main - # https://github.com/pandas-dev/pandas/issues/58690 - # check( - # assert_type( - # GB_S.apply(lambda x: x.resample("ME").interpolate(inplace=True)), None - # ), - # type(None), - # ) # pipe def g(val: Resampler[Series]) -> float: diff --git a/tests/test_interval.py b/tests/test_interval.py index 40a8583bd..a8e9c92b5 100644 --- a/tests/test_interval.py +++ b/tests/test_interval.py @@ -7,7 +7,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, - np_1darray, + np_1darray_bool, ) @@ -127,4 +127,4 @@ def test_interval_array_contains() -> None: ser = pd.Series(obj, index=df.index) arr = ser.array check(assert_type(arr.contains(df["A"]), "pd.Series[bool]"), pd.Series, np.bool_) - check(assert_type(arr.contains(3), np_1darray[np.bool]), np_1darray[np.bool]) + check(assert_type(arr.contains(3), np_1darray_bool), np_1darray_bool) diff --git a/tests/test_resampler.py b/tests/test_resampler.py index ad9f751d1..3a5986cdf 100644 --- a/tests/test_resampler.py +++ b/tests/test_resampler.py @@ -2,6 +2,7 @@ Hashable, Iterator, ) +from typing import TypeAlias import numpy as np import pandas as pd @@ -24,6 +25,11 @@ pytest_warns_bounded, ) +if not PD_LTE_23: + from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip +else: + Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] + DR = date_range("1999-1-1", periods=365, freq="D") DF_ = DataFrame(np.random.standard_normal((365, 1)), index=DR) S = DF_.iloc[:, 0] @@ -146,12 +152,19 @@ def test_interpolate() -> None: ) +# TODO: remove the whole test function when the warning and ValueError in pandas-dev/pandas#62847 are removed def test_interpolate_inplace() -> None: - if PD_LTE_23: - # Bug in main see https://github.com/pandas-dev/pandas/issues/58690 + with pytest_warns_bounded( + Pandas4Warning, + r"The 'inplace' keyword in DatetimeIndexResampler.interpolate is deprecated and will be removed in a future version. resample\(...\).interpolate is never inplace.", + lower="2.99", + ): check( - assert_type(DF.resample("ME").interpolate(inplace=True), None), type(None) + assert_type(DF.resample("ME").interpolate(inplace=False), DataFrame), + DataFrame, ) + if TYPE_CHECKING_INVALID_USAGE: + DF.resample("ME").interpolate(inplace=True) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] def test_pipe() -> None: @@ -361,12 +374,6 @@ def test_interpolate_series() -> None: check(assert_type(S.resample("ME").interpolate(method="time"), Series), Series) -def test_interpolate_inplace_series() -> None: - if PD_LTE_23: - # Bug in main see https://github.com/pandas-dev/pandas/issues/58690 - check(assert_type(S.resample("ME").interpolate(inplace=True), None), type(None)) - - def test_pipe_series() -> None: def f(val: "DatetimeIndexResampler[Series]") -> Series: assert isinstance(val, DatetimeIndexResampler) diff --git a/tests/test_string_accessors.py b/tests/test_string_accessors.py index 7ab9e769f..33033ee40 100644 --- a/tests/test_string_accessors.py +++ b/tests/test_string_accessors.py @@ -7,10 +7,9 @@ from typing_extensions import assert_type from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, - np_1darray, + np_1darray_bool, ) DATA = ["applep", "bananap", "Cherryp", "DATEp", "eGGpLANTp", "123p", "23.45p"] @@ -41,19 +40,11 @@ def test_string_accessors_boolean_series() -> None: _check( assert_type(s.str.contains("a"), "pd.Series[bool]"), ) - if PD_LTE_23: - # Bug in pandas 3.0 dev https://github.com/pandas-dev/pandas/issues/61942 - _check( - assert_type( - s.str.contains(re.compile(r"a"), regex=True), "pd.Series[bool]" - ), - ) + _check(assert_type(s.str.contains(re.compile(r"a"), regex=True), "pd.Series[bool]")) _check(assert_type(s.str.endswith("e"), "pd.Series[bool]")) _check(assert_type(s.str.endswith(("e", "f")), "pd.Series[bool]")) _check(assert_type(s.str.fullmatch("apple"), "pd.Series[bool]")) - if PD_LTE_23: - # Bug in 3.0 dev: https://github.com/pandas-dev/pandas/issues/61952 - _check(assert_type(s.str.fullmatch(re.compile(r"apple")), "pd.Series[bool]")) + _check(assert_type(s.str.fullmatch(re.compile(r"apple")), "pd.Series[bool]")) _check(assert_type(s.str.isalnum(), "pd.Series[bool]")) _check(assert_type(s.str.isalpha(), "pd.Series[bool]")) _check(assert_type(s.str.isdecimal(), "pd.Series[bool]")) @@ -64,49 +55,33 @@ def test_string_accessors_boolean_series() -> None: _check(assert_type(s.str.istitle(), "pd.Series[bool]")) _check(assert_type(s.str.isupper(), "pd.Series[bool]")) _check(assert_type(s.str.match("pp"), "pd.Series[bool]")) - if PD_LTE_23: - # Bug in 3.0 dev: https://github.com/pandas-dev/pandas/issues/61952 - _check(assert_type(s.str.match(re.compile(r"pp")), "pd.Series[bool]")) + _check(assert_type(s.str.match(re.compile(r"pp")), "pd.Series[bool]")) def test_string_accessors_boolean_index() -> None: idx = pd.Index(DATA) - _check = functools.partial(check, klass=np_1darray[np.bool]) - _check(assert_type(idx.str.startswith("a"), np_1darray[np.bool])) - _check( - assert_type(idx.str.startswith(("a", "b")), np_1darray[np.bool]), - ) + _check = functools.partial(check, klass=np_1darray_bool) + _check(assert_type(idx.str.startswith("a"), np_1darray_bool)) _check( - assert_type(idx.str.contains("a"), np_1darray[np.bool]), - ) - if PD_LTE_23: - # Bug in pandas 3.0 dev https://github.com/pandas-dev/pandas/issues/61942 - _check( - assert_type( - idx.str.contains(re.compile(r"a"), regex=True), np_1darray[np.bool] - ), - ) - _check(assert_type(idx.str.endswith("e"), np_1darray[np.bool])) - _check(assert_type(idx.str.endswith(("e", "f")), np_1darray[np.bool])) - _check(assert_type(idx.str.fullmatch("apple"), np_1darray[np.bool])) - if PD_LTE_23: - # Bug in 3.0 dev: https://github.com/pandas-dev/pandas/issues/61952 - _check( - assert_type(idx.str.fullmatch(re.compile(r"apple")), np_1darray[np.bool]) - ) - _check(assert_type(idx.str.isalnum(), np_1darray[np.bool])) - _check(assert_type(idx.str.isalpha(), np_1darray[np.bool])) - _check(assert_type(idx.str.isdecimal(), np_1darray[np.bool])) - _check(assert_type(idx.str.isdigit(), np_1darray[np.bool])) - _check(assert_type(idx.str.isnumeric(), np_1darray[np.bool])) - _check(assert_type(idx.str.islower(), np_1darray[np.bool])) - _check(assert_type(idx.str.isspace(), np_1darray[np.bool])) - _check(assert_type(idx.str.istitle(), np_1darray[np.bool])) - _check(assert_type(idx.str.isupper(), np_1darray[np.bool])) - _check(assert_type(idx.str.match("pp"), np_1darray[np.bool])) - if PD_LTE_23: - # Bug in 3.0 dev: https://github.com/pandas-dev/pandas/issues/61952 - _check(assert_type(idx.str.match(re.compile(r"pp")), np_1darray[np.bool])) + assert_type(idx.str.startswith(("a", "b")), np_1darray_bool), + ) + _check(assert_type(idx.str.contains("a"), np_1darray_bool)) + _check(assert_type(idx.str.contains(re.compile(r"a"), regex=True), np_1darray_bool)) + _check(assert_type(idx.str.endswith("e"), np_1darray_bool)) + _check(assert_type(idx.str.endswith(("e", "f")), np_1darray_bool)) + _check(assert_type(idx.str.fullmatch("apple"), np_1darray_bool)) + _check(assert_type(idx.str.fullmatch(re.compile(r"apple")), np_1darray_bool)) + _check(assert_type(idx.str.isalnum(), np_1darray_bool)) + _check(assert_type(idx.str.isalpha(), np_1darray_bool)) + _check(assert_type(idx.str.isdecimal(), np_1darray_bool)) + _check(assert_type(idx.str.isdigit(), np_1darray_bool)) + _check(assert_type(idx.str.isnumeric(), np_1darray_bool)) + _check(assert_type(idx.str.islower(), np_1darray_bool)) + _check(assert_type(idx.str.isspace(), np_1darray_bool)) + _check(assert_type(idx.str.istitle(), np_1darray_bool)) + _check(assert_type(idx.str.isupper(), np_1darray_bool)) + _check(assert_type(idx.str.match("pp"), np_1darray_bool)) + _check(assert_type(idx.str.match(re.compile(r"pp")), np_1darray_bool)) def test_string_accessors_integer_series() -> None: diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index e495209f7..6d599ecfa 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -29,8 +29,12 @@ TYPE_CHECKING_INVALID_USAGE, check, np_1darray, + np_1darray_bool, + np_1darray_bytes, np_1darray_dt, np_1darray_int64, + np_1darray_object, + np_1darray_str, np_1darray_td, pytest_warns_bounded, ) @@ -48,7 +52,7 @@ ) if not PD_LTE_23: - from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip + from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue,reportRedeclaration] # isort: skip else: Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] @@ -273,12 +277,12 @@ def test_comparisons_datetimeindex() -> None: # GH 74 dti = pd.date_range("2000-01-01", "2000-01-10") ts = pd.Timestamp("2000-01-05") - check(assert_type((dti < ts), np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type((dti > ts), np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type((dti >= ts), np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type((dti <= ts), np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type((dti == ts), np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type((dti != ts), np_1darray[np.bool]), np_1darray[np.bool]) + check(assert_type((dti < ts), np_1darray_bool), np_1darray_bool) + check(assert_type((dti > ts), np_1darray_bool), np_1darray_bool) + check(assert_type((dti >= ts), np_1darray_bool), np_1darray_bool) + check(assert_type((dti <= ts), np_1darray_bool), np_1darray_bool) + check(assert_type((dti == ts), np_1darray_bool), np_1darray_bool) + check(assert_type((dti != ts), np_1darray_bool), np_1darray_bool) def test_to_datetime_nat() -> None: @@ -348,8 +352,8 @@ def test_series_dt_accessors() -> None: upper="2.3.99", ): check( - assert_type(s0.dt.to_pydatetime(), np_1darray[np.object_]), - np_1darray[np.object_] if PD_LTE_23 else pd.Series, + assert_type(s0.dt.to_pydatetime(), np_1darray_object), + np_1darray_object if PD_LTE_23 else pd.Series, dt.datetime, ) s0_local = s0.dt.tz_localize("UTC") @@ -520,8 +524,8 @@ def test_series_dt_accessors() -> None: ), ): check( - assert_type(s2.dt.to_pytimedelta(), np_1darray[np.object_]), - np_1darray[np.object_], + assert_type(s2.dt.to_pytimedelta(), np_1darray_object), + np_1darray_object, dt.timedelta, ) check(assert_type(s2.dt.total_seconds(), "pd.Series[float]"), pd.Series, float) @@ -607,11 +611,9 @@ def test_datetimeindex_accessors() -> None: i0 = pd.date_range(start="2022-06-01", periods=10) check(assert_type(i0, pd.DatetimeIndex), pd.DatetimeIndex, pd.Timestamp) - check(assert_type(i0.date, np_1darray[np.object_]), np_1darray[np.object_], dt.date) - check(assert_type(i0.time, np_1darray[np.object_]), np_1darray[np.object_], dt.time) - check( - assert_type(i0.timetz, np_1darray[np.object_]), np_1darray[np.object_], dt.time - ) + check(assert_type(i0.date, np_1darray_object), np_1darray_object, dt.date) + check(assert_type(i0.time, np_1darray_object), np_1darray_object, dt.time) + check(assert_type(i0.timetz, np_1darray_object), np_1darray_object, dt.time) check(assert_type(i0.year, "pd.Index[int]"), pd.Index, np.int32) check(assert_type(i0.month, "pd.Index[int]"), pd.Index, np.int32) check(assert_type(i0.day, "pd.Index[int]"), pd.Index, np.int32) @@ -626,13 +628,13 @@ def test_datetimeindex_accessors() -> None: check(assert_type(i0.dayofyear, "pd.Index[int]"), pd.Index, np.int32) check(assert_type(i0.day_of_year, "pd.Index[int]"), pd.Index, np.int32) check(assert_type(i0.quarter, "pd.Index[int]"), pd.Index, np.int32) - check(assert_type(i0.is_month_start, np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type(i0.is_month_end, np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type(i0.is_quarter_start, np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type(i0.is_quarter_end, np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type(i0.is_year_start, np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type(i0.is_year_end, np_1darray[np.bool]), np_1darray[np.bool]) - check(assert_type(i0.is_leap_year, np_1darray[np.bool]), np_1darray[np.bool]) + check(assert_type(i0.is_month_start, np_1darray_bool), np_1darray_bool) + check(assert_type(i0.is_month_end, np_1darray_bool), np_1darray_bool) + check(assert_type(i0.is_quarter_start, np_1darray_bool), np_1darray_bool) + check(assert_type(i0.is_quarter_end, np_1darray_bool), np_1darray_bool) + check(assert_type(i0.is_year_start, np_1darray_bool), np_1darray_bool) + check(assert_type(i0.is_year_end, np_1darray_bool), np_1darray_bool) + check(assert_type(i0.is_leap_year, np_1darray_bool), np_1darray_bool) check(assert_type(i0.daysinmonth, "pd.Index[int]"), pd.Index, np.int32) check(assert_type(i0.days_in_month, "pd.Index[int]"), pd.Index, np.int32) check(assert_type(i0.tz, dt.tzinfo | None), type(None)) @@ -640,8 +642,8 @@ def test_datetimeindex_accessors() -> None: check(assert_type(i0.isocalendar(), pd.DataFrame), pd.DataFrame) check(assert_type(i0.to_period("D"), pd.PeriodIndex), pd.PeriodIndex, pd.Period) check( - assert_type(i0.to_pydatetime(), np_1darray[np.object_]), - np_1darray[np.object_], + assert_type(i0.to_pydatetime(), np_1darray_object), + np_1darray_object, dt.datetime, ) ilocal = i0.tz_localize("UTC") @@ -683,8 +685,8 @@ def test_timedeltaindex_accessors() -> None: check(assert_type(i0.nanoseconds, pd.Index), pd.Index, np.integer) check(assert_type(i0.components, pd.DataFrame), pd.DataFrame) check( - assert_type(i0.to_pytimedelta(), np_1darray[np.object_]), - np_1darray[np.object_], + assert_type(i0.to_pytimedelta(), np_1darray_object), + np_1darray_object, dt.timedelta, ) check(assert_type(i0.total_seconds(), pd.Index), pd.Index, float) @@ -908,37 +910,33 @@ def test_series_types_to_numpy() -> None: np.datetime64, ) check( - assert_type(p_s.to_numpy(), np_1darray[np.object_]), - np_1darray[np.object_], + assert_type(p_s.to_numpy(), np_1darray_object), + np_1darray_object, dtype=pd.Period, ) check( - assert_type(p_s.to_numpy(na_value=pd.Timestamp(1)), np_1darray[np.object_]), - np_1darray[np.object_], + assert_type(p_s.to_numpy(na_value=pd.Timestamp(1)), np_1darray_object), + np_1darray_object, dtype=pd.Period, ) check( - assert_type(o_s.to_numpy(), np_1darray[np.object_]), - np_1darray[np.object_], + assert_type(o_s.to_numpy(), np_1darray_object), + np_1darray_object, dtype=pd.DateOffset, ) check( - assert_type( - o_s.to_numpy(na_value=pd.Timedelta(days=1)), np_1darray[np.object_] - ), - np_1darray[np.object_], + assert_type(o_s.to_numpy(na_value=pd.Timedelta(days=1)), np_1darray_object), + np_1darray_object, dtype=pd.DateOffset, ) check( - assert_type(i_s.to_numpy(), np_1darray[np.object_]), - np_1darray[np.object_], + assert_type(i_s.to_numpy(), np_1darray_object), + np_1darray_object, dtype=pd.Interval, ) check( - assert_type( - i_s.to_numpy(na_value=pd.Timedelta(days=1)), np_1darray[np.object_] - ), - np_1darray[np.object_], + assert_type(i_s.to_numpy(na_value=pd.Timedelta(days=1)), np_1darray_object), + np_1darray_object, dtype=pd.Interval, ) @@ -960,13 +958,11 @@ def test_series_types_to_numpy() -> None: ) check( assert_type(o_s.to_numpy(dtype="bytes", copy=True), np_1darray), - np_1darray, - dtype=np.bytes_, + np_1darray_bytes, ) check( assert_type(i_s.to_numpy(dtype="bytes", copy=True), np_1darray), - np_1darray, - dtype=np.bytes_, + np_1darray_bytes, ) # passed dtype-like with statically known generic @@ -996,20 +992,12 @@ def test_series_types_to_numpy() -> None: np.int64, ) check( - assert_type(o_s.to_numpy(dtype=np.bytes_), np_1darray[np.bytes_]), - np_1darray, - dtype=np.bytes_, + assert_type(o_s.to_numpy(dtype=np.bytes_), np_1darray_bytes), np_1darray_bytes ) check( - assert_type(i_s.to_numpy(dtype=np.bytes_), np_1darray[np.bytes_]), - np_1darray, - dtype=np.bytes_, - ) - check( - assert_type(i_s.to_numpy(dtype=np.str_), np_1darray[np.str_]), - np_1darray, - dtype=np.str_, + assert_type(i_s.to_numpy(dtype=np.bytes_), np_1darray_bytes), np_1darray_bytes ) + check(assert_type(i_s.to_numpy(dtype=np.str_), np_1darray_str), np_1darray_str) def test_index_types_to_numpy() -> None: @@ -1032,25 +1020,23 @@ def test_index_types_to_numpy() -> None: np.datetime64, ) check( - assert_type(p_i.to_numpy(), np_1darray[np.object_]), - np_1darray[np.object_], + assert_type(p_i.to_numpy(), np_1darray_object), + np_1darray_object, dtype=pd.Period, ) check( - assert_type(p_i.to_numpy(na_value=pd.Timestamp(1)), np_1darray[np.object_]), - np_1darray[np.object_], + assert_type(p_i.to_numpy(na_value=pd.Timestamp(1)), np_1darray_object), + np_1darray_object, dtype=pd.Period, ) check( - assert_type(i_i.to_numpy(), np_1darray[np.object_]), - np_1darray[np.object_], + assert_type(i_i.to_numpy(), np_1darray_object), + np_1darray_object, dtype=pd.Interval, ) check( - assert_type( - i_i.to_numpy(na_value=pd.Timedelta(days=1)), np_1darray[np.object_] - ), - np_1darray[np.object_], + assert_type(i_i.to_numpy(na_value=pd.Timedelta(days=1)), np_1darray_object), + np_1darray_object, dtype=pd.Interval, ) @@ -1072,8 +1058,7 @@ def test_index_types_to_numpy() -> None: ) check( assert_type(i_i.to_numpy(dtype="bytes", copy=True), np_1darray), - np_1darray, - dtype=np.bytes_, + np_1darray_bytes, ) # passed dtype-like with statically known generic @@ -1093,9 +1078,7 @@ def test_index_types_to_numpy() -> None: np.int64, ) check( - assert_type(i_i.to_numpy(dtype=np.bytes_), np_1darray[np.bytes_]), - np_1darray, - dtype=np.bytes_, + assert_type(i_i.to_numpy(dtype=np.bytes_), np_1darray_bytes), np_1darray_bytes )