Skip to content
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

Added ArrayLike In Series.clip #443

Merged
merged 4 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ from pandas._typing import (
AggFuncTypeBase,
AggFuncTypeDictFrame,
AggFuncTypeSeriesToFrame,
AnyArrayLike,
ArrayLike,
Axes,
Axis,
Expand Down Expand Up @@ -1065,8 +1066,8 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
) -> Scalar | Series[S1]: ...
def clip(
self,
lower: float | None = ...,
upper: float | None = ...,
lower: AnyArrayLike | float | None = ...,
upper: AnyArrayLike | float | None = ...,
axis: SeriesAxisType | None = ...,
inplace: _bool = ...,
*args,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,3 +1330,12 @@ def test_logical_operators() -> None:
pd.Series,
bool,
)


def test_AnyArrayLike_and_clip() -> None:
ser = pd.Series([1, 2, 3])
s1=ser.clip(upper=ser)
s2=ser.clip(upper=ser)
check(assert_type(s1, pd.Series), pd.Series, pd.Series[Any])
check(assert_type(s2, pd.Series), pd.Series, pd.Series[Any])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check(assert_type(s2, pd.Series), pd.Series)

If you know the type of the object inside the Series, then you do check(assert_type(s2, pd.Series), pd.Series, float) (for example). But here we don't know the type, so we just leave out that last argument to check.

Look at the code for check to see how it works

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks sir read the check code

# assert_type(ser.clip(lower=ser), pd.Series)