-
-
Notifications
You must be signed in to change notification settings - Fork 156
Add variance checks to aggregation tests and type assertions #1546
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4610,14 +4610,33 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): | |||||
| **kwargs: Any, | ||||||
| ) -> np_1darray: ... | ||||||
| def tolist(self) -> list[S1]: ... | ||||||
| @overload | ||||||
| def var( | ||||||
| self, | ||||||
| self: Series[Never], | ||||||
| axis: AxisIndex | None = 0, | ||||||
| skipna: _bool | None = True, | ||||||
| ddof: int = 1, | ||||||
| numeric_only: _bool = False, | ||||||
| **kwargs: Any, | ||||||
| ) -> Scalar: ... | ||||||
| ) -> float: ... | ||||||
| @overload | ||||||
| def var( | ||||||
| self: Series[complex], | ||||||
| axis: AxisIndex | None = 0, | ||||||
| skipna: _bool | None = True, | ||||||
| ddof: int = 1, | ||||||
| numeric_only: _bool = False, | ||||||
| **kwargs: Any, | ||||||
| ) -> np.float64: ... | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| @overload | ||||||
| def var( | ||||||
| self: SupportsGetItem[Scalar, SupportsTruedivInt[S2]], | ||||||
| axis: AxisIndex | None = 0, | ||||||
| skipna: _bool | None = True, | ||||||
| ddof: int = 1, | ||||||
| numeric_only: _bool = False, | ||||||
| **kwargs: Any, | ||||||
| ) -> S2: ... | ||||||
| # Rename axis with `mapper`, `axis`, and `inplace=True` | ||||||
| @overload | ||||||
| def rename_axis( | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,27 +14,31 @@ def test_agg_any_float() -> None: | |
| check(assert_type(series.mean(), float), np.float64) | ||
| check(assert_type(series.median(), float), np.float64) | ||
| check(assert_type(series.std(), float), np.float64) | ||
| check(assert_type(series.var(), float), np.float64) | ||
|
|
||
|
|
||
| def test_agg_bool() -> None: | ||
| series = pd.Series([True, False, True]) | ||
| check(assert_type(series.mean(), float), np.float64) | ||
| check(assert_type(series.median(), float), np.float64) | ||
| check(assert_type(series.std(), float), np.float64) | ||
| check(assert_type(series.var(), float), np.float64) | ||
|
|
||
|
|
||
| def test_agg_int() -> None: | ||
| series = pd.Series([3, 1, 2]) | ||
| check(assert_type(series.mean(), float), np.float64) | ||
| check(assert_type(series.median(), float), np.float64) | ||
| check(assert_type(series.std(), float), np.float64) | ||
| check(assert_type(series.var(), float), np.float64) | ||
|
|
||
|
|
||
| def test_agg_float() -> None: | ||
| series = pd.Series([3.0, float("nan"), 2.0]) | ||
| check(assert_type(series.mean(), float), np.float64) | ||
| check(assert_type(series.median(), float), np.float64) | ||
| check(assert_type(series.std(), float), np.float64) | ||
| check(assert_type(series.var(), float), np.float64) | ||
|
|
||
|
|
||
| def test_agg_complex() -> None: | ||
|
|
@@ -57,6 +61,11 @@ def test_agg_complex() -> None: | |
| ), | ||
| ): | ||
| check(assert_type(series.std(), np.float64), np.float64) | ||
| with pytest_warns_bounded( | ||
| np.exceptions.ComplexWarning, | ||
| r"Casting complex values to real discards the imaginary part", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use |
||
| ): | ||
| check(assert_type(series.var(), np.float64), np.float64) | ||
|
|
||
|
|
||
| def test_agg_str() -> None: | ||
|
|
@@ -65,6 +74,7 @@ def test_agg_str() -> None: | |
| series.mean() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] | ||
| series.median() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] | ||
| series.std() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] | ||
| series.var() # type: ignore[misc] # pyright: ignore[reportAttributeAccessIssue] | ||
|
|
||
|
|
||
| def test_agg_ts() -> None: | ||
|
|
@@ -83,3 +93,4 @@ def test_agg_td() -> None: | |
| check(assert_type(series.mean(), pd.Timedelta), pd.Timedelta) | ||
| check(assert_type(series.median(), pd.Timedelta), pd.Timedelta) | ||
| check(assert_type(series.std(), pd.Timedelta), pd.Timedelta) | ||
| # Note: var() is not supported for Timedelta series at runtime | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use Error is preferable over |
||
Uh oh!
There was an error while loading. Please reload this page.