Skip to content

Type tolerance in reindex_like, remove unused function #1107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 0 additions & 16 deletions pandas-stubs/core/construction.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ from collections.abc import Sequence

import numpy as np
from pandas.core.arrays.base import ExtensionArray
from pandas.core.indexes.api import Index
from pandas.core.series import Series

from pandas._typing import (
ArrayLike,
Dtype,
)

from pandas.core.dtypes.dtypes import ExtensionDtype

Expand All @@ -22,12 +15,3 @@ def sanitize_array(
data, index, dtype=..., copy: bool = ..., raise_cast_failure: bool = ...
): ...
def is_empty_data(data) -> bool: ...
def create_series_with_explicit_dtype(
data=...,
index: ArrayLike | Index | None = ...,
dtype: Dtype | None = ...,
name: str | None = ...,
copy: bool = ...,
fastpath: bool = ...,
dtype_if_empty: Dtype = ...,
) -> Series: ...
2 changes: 1 addition & 1 deletion pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
method: _str | FillnaOptions | Literal["nearest"] | None = ...,
copy: _bool = ...,
limit: int | None = ...,
tolerance=...,
tolerance: Scalar | AnyArrayLike | Sequence[Scalar] = ...,
) -> Self: ...
# Rename axis with `mapper`, `axis`, and `inplace=True`
@overload
Expand Down
9 changes: 3 additions & 6 deletions pandas-stubs/core/reshape/encoding.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ from collections.abc import (
Iterable,
)

from pandas import (
DataFrame,
Series,
)
from pandas import DataFrame

from pandas._typing import (
ArrayLike,
AnyArrayLike,
Dtype,
HashableT1,
HashableT2,
)

def get_dummies(
data: ArrayLike | DataFrame | Series,
data: AnyArrayLike | DataFrame,
prefix: str | Iterable[str] | dict[HashableT1, str] | None = ...,
prefix_sep: str = ...,
dummy_na: bool = ...,
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
method: _str | FillnaOptions | Literal["nearest"] | None = ...,
copy: _bool = ...,
limit: int | None = ...,
tolerance: float | None = ...,
tolerance: Scalar | AnyArrayLike | Sequence[Scalar] = ...,
) -> Self: ...
@overload
def fillna(
Expand Down
12 changes: 12 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2663,6 +2663,18 @@ def test_frame_reindex() -> None:
df.reindex([2, 1, 0])


def test_frame_reindex_like() -> None:
# GH 84
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2])
other = pd.DataFrame({"a": [1, 2]}, index=[1, 0])
check(
assert_type(
df.reindex_like(other, method="nearest", tolerance=[0.5, 0.2]), pd.DataFrame
),
pd.DataFrame,
)


def test_frame_ndarray_assignmment() -> None:
# GH 100
df_a = pd.DataFrame({"a": [0.0] * 10})
Expand Down
18 changes: 18 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3552,3 +3552,21 @@ def test_series_int_float() -> None:
check(
assert_type(pd.Series([1, 2.0, 3]), "pd.Series[float]"), pd.Series, np.float64
)


def test_series_reindex() -> None:
s = pd.Series([1, 2, 3], index=[0, 1, 2])
check(assert_type(s.reindex([2, 1, 0]), "pd.Series[int]"), pd.Series, np.integer)


def test_series_reindex_like() -> None:
s = pd.Series([1, 2, 3], index=[0, 1, 2])
other = pd.Series([1, 2], index=[1, 0])
check(
assert_type(
s.reindex_like(other, method="nearest", tolerance=[0.5, 0.2]),
"pd.Series[int]",
),
pd.Series,
np.integer,
)