Skip to content

CI/TYP: Window typing followup #40392

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
Mar 12, 2021
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
4 changes: 3 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11014,7 +11014,9 @@ def ewm(
times: Optional[Union[str, np.ndarray, FrameOrSeries]] = None,
) -> ExponentialMovingWindow:
axis = self._get_axis_number(axis)
return ExponentialMovingWindow(
# error: Value of type variable "FrameOrSeries" of "ExponentialMovingWindow"
# cannot be "object"
return ExponentialMovingWindow( # type: ignore[type-var]
self,
com=com,
span=span,
Expand Down
7 changes: 2 additions & 5 deletions pandas/core/window/expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
Dict,
Optional,
Tuple,
Union,
)

import numpy as np

from pandas._typing import (
Axis,
FrameOrSeries,
Expand Down Expand Up @@ -589,7 +586,7 @@ def quantile(
)
def cov(
self,
other: Optional[Union[np.ndarray, FrameOrSeriesUnion]] = None,
other: Optional[FrameOrSeriesUnion] = None,
Copy link
Member

Choose a reason for hiding this comment

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

How is this change correct? Or is the docstring not correct? (which says that other can also be an ndarray)

Copy link
Member Author

Choose a reason for hiding this comment

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

At least on master, passing a numpy array raises

In [1]: pd.Series(range(10)).expanding().cov(np.arange(10))
Exception: Input arrays must be of the same type!

as well there's a test, test_different_input_array_raise_exception that checks that an Exception is raised with a numpy array.

So I can follow up fixing the documentation

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good!

pairwise: Optional[bool] = None,
ddof: int = 1,
**kwargs,
Expand Down Expand Up @@ -654,7 +651,7 @@ def cov(
)
def corr(
self,
other: Optional[Union[np.ndarray, FrameOrSeriesUnion]] = None,
other: Optional[FrameOrSeriesUnion] = None,
pairwise: Optional[bool] = None,
ddof: int = 1,
**kwargs,
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ def quantile(self, quantile: float, interpolation: str = "linear", **kwargs):

def cov(
self,
other: Optional[Union[np.ndarray, FrameOrSeriesUnion]] = None,
other: Optional[FrameOrSeriesUnion] = None,
pairwise: Optional[bool] = None,
ddof: int = 1,
**kwargs,
Expand Down Expand Up @@ -1392,7 +1392,7 @@ def cov_func(x, y):

def corr(
self,
other: Optional[Union[np.ndarray, FrameOrSeriesUnion]] = None,
other: Optional[FrameOrSeriesUnion] = None,
pairwise: Optional[bool] = None,
ddof: int = 1,
**kwargs,
Expand Down Expand Up @@ -2137,7 +2137,7 @@ def quantile(self, quantile: float, interpolation: str = "linear", **kwargs):
)
def cov(
self,
other: Optional[Union[np.ndarray, FrameOrSeriesUnion]] = None,
other: Optional[FrameOrSeriesUnion] = None,
pairwise: Optional[bool] = None,
ddof: int = 1,
**kwargs,
Expand Down Expand Up @@ -2262,7 +2262,7 @@ def cov(
)
def corr(
self,
other: Optional[Union[np.ndarray, FrameOrSeriesUnion]] = None,
other: Optional[FrameOrSeriesUnion] = None,
pairwise: Optional[bool] = None,
ddof: int = 1,
**kwargs,
Expand Down