Skip to content

Commit a32c467

Browse files
authored
Type tolerance in reindex_like, remove unused function (#1107)
* Type `tolerance` in `reindex_like`, remove unused function * revert unrelated, use assert_type * another assert_type * one more * 🔥 remove generic reindex_like
1 parent 54b15c3 commit a32c467

File tree

7 files changed

+35
-32
lines changed

7 files changed

+35
-32
lines changed

pandas-stubs/core/construction.pyi

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ from collections.abc import Sequence
22

33
import numpy as np
44
from pandas.core.arrays.base import ExtensionArray
5-
from pandas.core.indexes.api import Index
6-
from pandas.core.series import Series
7-
8-
from pandas._typing import (
9-
ArrayLike,
10-
Dtype,
11-
)
125

136
from pandas.core.dtypes.dtypes import ExtensionDtype
147

@@ -22,12 +15,3 @@ def sanitize_array(
2215
data, index, dtype=..., copy: bool = ..., raise_cast_failure: bool = ...
2316
): ...
2417
def is_empty_data(data) -> bool: ...
25-
def create_series_with_explicit_dtype(
26-
data=...,
27-
index: ArrayLike | Index | None = ...,
28-
dtype: Dtype | None = ...,
29-
name: str | None = ...,
30-
copy: bool = ...,
31-
fastpath: bool = ...,
32-
dtype_if_empty: Dtype = ...,
33-
) -> Series: ...

pandas-stubs/core/frame.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2127,7 +2127,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
21272127
method: _str | FillnaOptions | Literal["nearest"] | None = ...,
21282128
copy: _bool = ...,
21292129
limit: int | None = ...,
2130-
tolerance=...,
2130+
tolerance: Scalar | AnyArrayLike | Sequence[Scalar] = ...,
21312131
) -> Self: ...
21322132
# Rename axis with `mapper`, `axis`, and `inplace=True`
21332133
@overload

pandas-stubs/core/generic.pyi

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,6 @@ class NDFrame(indexing.IndexingMixin):
294294
) -> _str: ...
295295
def take(self, indices, axis=..., **kwargs) -> Self: ...
296296
def __delitem__(self, idx: Hashable) -> None: ...
297-
def reindex_like(
298-
self,
299-
other,
300-
method: _str | None = ...,
301-
copy: _bool = ...,
302-
limit=...,
303-
tolerance=...,
304-
) -> Self: ...
305297
@overload
306298
def drop(
307299
self,

pandas-stubs/core/reshape/encoding.pyi

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ from collections.abc import (
33
Iterable,
44
)
55

6-
from pandas import (
7-
DataFrame,
8-
Series,
9-
)
6+
from pandas import DataFrame
107

118
from pandas._typing import (
12-
ArrayLike,
9+
AnyArrayLike,
1310
Dtype,
1411
HashableT1,
1512
HashableT2,
1613
)
1714

1815
def get_dummies(
19-
data: ArrayLike | DataFrame | Series,
16+
data: AnyArrayLike | DataFrame,
2017
prefix: str | Iterable[str] | dict[HashableT1, str] | None = ...,
2118
prefix_sep: str = ...,
2219
dummy_na: bool = ...,

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
11511151
method: _str | FillnaOptions | Literal["nearest"] | None = ...,
11521152
copy: _bool = ...,
11531153
limit: int | None = ...,
1154-
tolerance: float | None = ...,
1154+
tolerance: Scalar | AnyArrayLike | Sequence[Scalar] = ...,
11551155
) -> Self: ...
11561156
@overload
11571157
def fillna(

tests/test_frame.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,18 @@ def test_frame_reindex() -> None:
26632663
df.reindex([2, 1, 0])
26642664

26652665

2666+
def test_frame_reindex_like() -> None:
2667+
# GH 84
2668+
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2])
2669+
other = pd.DataFrame({"a": [1, 2]}, index=[1, 0])
2670+
check(
2671+
assert_type(
2672+
df.reindex_like(other, method="nearest", tolerance=[0.5, 0.2]), pd.DataFrame
2673+
),
2674+
pd.DataFrame,
2675+
)
2676+
2677+
26662678
def test_frame_ndarray_assignmment() -> None:
26672679
# GH 100
26682680
df_a = pd.DataFrame({"a": [0.0] * 10})

tests/test_series.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,3 +3552,21 @@ def test_series_int_float() -> None:
35523552
check(
35533553
assert_type(pd.Series([1, 2.0, 3]), "pd.Series[float]"), pd.Series, np.float64
35543554
)
3555+
3556+
3557+
def test_series_reindex() -> None:
3558+
s = pd.Series([1, 2, 3], index=[0, 1, 2])
3559+
check(assert_type(s.reindex([2, 1, 0]), "pd.Series[int]"), pd.Series, np.integer)
3560+
3561+
3562+
def test_series_reindex_like() -> None:
3563+
s = pd.Series([1, 2, 3], index=[0, 1, 2])
3564+
other = pd.Series([1, 2], index=[1, 0])
3565+
check(
3566+
assert_type(
3567+
s.reindex_like(other, method="nearest", tolerance=[0.5, 0.2]),
3568+
"pd.Series[int]",
3569+
),
3570+
pd.Series,
3571+
np.integer,
3572+
)

0 commit comments

Comments
 (0)