Skip to content

Revert "gh:552 - Corrected Series.mean return type" #647

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 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ IndexIterScalar: TypeAlias = (
| float
| Timestamp
| Timedelta
| np.integer
| np.float_
)
Scalar: TypeAlias = IndexIterScalar | complex
ScalarT = TypeVar("ScalarT", bound=Scalar)
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 @@ -1609,7 +1609,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
level: None = ...,
numeric_only: _bool = ...,
**kwargs,
) -> np.float64: ...
) -> float: ...
def median(
self,
axis: AxisIndex | None = ...,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,12 +2019,12 @@ def test_groupby_apply() -> None:
# GH 167
df = pd.DataFrame({"col1": [1, 2, 3], "col2": [4, 5, 6]})

def sum_mean(x: pd.DataFrame) -> np.float64:
def sum_mean(x: pd.DataFrame) -> float:
return x.sum().mean()

check(assert_type(df.groupby("col1").apply(sum_mean), pd.Series), pd.Series)

lfunc: Callable[[pd.DataFrame], np.float64] = lambda x: x.sum().mean()
lfunc: Callable[[pd.DataFrame], float] = lambda x: x.sum().mean()
check(
assert_type(df.groupby("col1").apply(lfunc), pd.Series),
pd.Series,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def g(val: DataFrame) -> Series:

check(assert_type(DF.resample("m").pipe(g), DataFrame), DataFrame)

def h(val: DataFrame) -> np.float64:
def h(val: DataFrame) -> float:
return val.mean().mean()

check(assert_type(DF.resample("m").pipe(h), Series), Series)
Expand Down Expand Up @@ -245,10 +245,10 @@ def test_aggregate_series() -> None:
DataFrame,
)

def f(val: Series) -> np.float64:
def f(val: Series) -> float:
return val.mean()

check(assert_type(S.resample("m").aggregate(f), _AggRetType), pd.Series)
check(assert_type(S.resample("m").aggregate(f), _AggRetType), Series)


def test_asfreq_series() -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ def test_types_rank() -> None:

def test_types_mean() -> None:
s = pd.Series([1, 2, 3, np.nan])
check(assert_type(s.mean(), np.float64), np.float64)
f1: float = s.mean()
s1: pd.Series = s.groupby(level=0).mean()
f2: np.float64 = s.mean(skipna=False)
f3: np.float64 = s.mean(numeric_only=False)
f2: float = s.mean(skipna=False)
f3: float = s.mean(numeric_only=False)


def test_types_median() -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_windowing.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_rolling_basic_math_series() -> None:
def test_rolling_apply_series() -> None:
check(assert_type(S.rolling(10).apply(np.mean), Series), Series)

def _mean(df: Series) -> np.float64:
def _mean(df: Series) -> float:
return df.mean()

check(assert_type(S.rolling(10).apply(_mean), Series), Series)
Expand All @@ -163,7 +163,7 @@ def test_rolling_aggregate_series() -> None:
check(assert_type(S.rolling(10).aggregate(np.mean), Series), Series)
check(assert_type(S.rolling(10).aggregate("mean"), Series), Series)

def _mean(s: Series) -> np.float64:
def _mean(s: Series) -> float:
return s.mean()

check(assert_type(S.rolling(10).aggregate(_mean), Series), Series)
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_expanding_basic_math_series() -> None:
def test_expanding_apply_series() -> None:
check(assert_type(S.expanding(10).apply(np.mean), Series), Series)

def _mean(df: Series) -> np.float64:
def _mean(df: Series) -> float:
return df.mean()

check(assert_type(S.expanding(10).apply(_mean), Series), Series)
Expand Down