Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions pandas-stubs/core/resample.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,12 @@ 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 = ...,
*,
axis: Axis = ...,
limit: int | None = ...,
inplace: Literal[False] = False,
limit_direction: Literal["forward", "backward", "both"] = ...,
limit_area: Literal["inside", "outside"] | None = ...,
**kwargs: Any,
Expand Down
3 changes: 2 additions & 1 deletion tests/arrays/test_extension_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from tests import (
check,
np_1darray,
np_1darray_intp,
)


Expand Down Expand Up @@ -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)
5 changes: 2 additions & 3 deletions tests/indexes/test_categoricalindex.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from __future__ import annotations

import numpy as np
import pandas as pd
from typing_extensions import (
assert_type,
)

from tests import (
check,
np_1darray,
np_1darray_intp,
)


Expand All @@ -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,
)

Expand Down
29 changes: 12 additions & 17 deletions tests/indexes/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

from tests import (
check,
np_1darray,
np_1darray_bool,
np_1darray_intp,
)


Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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,
)


Expand Down
47 changes: 19 additions & 28 deletions tests/indexes/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)


Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
47 changes: 11 additions & 36 deletions tests/indexes/test_rangeindex.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,54 @@
from __future__ import annotations

import numpy as np
import pandas as pd
from typing_extensions import (
assert_type,
)

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],
)
Loading