Skip to content

TYP: aggregations.pyx #41029

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 4 commits into from
Apr 28, 2021
Merged

TYP: aggregations.pyx #41029

merged 4 commits into from
Apr 28, 2021

Conversation

jbrockmendel
Copy link
Member

@mroeschke the type:ignores added in ewm.py look like potential bugs. any thoughts?

@jbrockmendel jbrockmendel added the Typing type annotations, mypy/pyright type checking label Apr 19, 2021
self.min_periods,
# error: Argument 4 to "ewmcov" has incompatible type
# "Optional[int]"; expected "int"
self.min_periods, # type: ignore[arg-type]
Copy link
Member

Choose a reason for hiding this comment

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

The EWM subclass ensures this is set to int before passing to the parent class which has Optional[int] typing

@@ -1068,7 +1071,10 @@ def sum(self, *args, **kwargs):
def mean(self, *args, **kwargs):
nv.validate_window_func("mean", args, kwargs)
window_func = window_aggregations.roll_weighted_mean
return self._apply(window_func, name="mean", **kwargs)
# error: Argument 1 to "_apply" of "Window" has incompatible type
Copy link
Member

Choose a reason for hiding this comment

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

EWM doesn't subclass Window so this can be ignored

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @jbrockmendel generally lgtm

end: np.ndarray, # np.ndarray[np.int64]
minp: int, # int64_t
quantile: float, # float64_t
interpolation: str,
Copy link
Member

Choose a reason for hiding this comment

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

could use Literal here?

start: np.ndarray, # np.ndarray[np.int64]
end: np.ndarray, # np.ndarray[np.int64]
minp: int, # int64_t
function: object,
Copy link
Member

Choose a reason for hiding this comment

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

callable? Callable[..., Any] used in _generate_cython_apply_func

raw: bool,
args: tuple,
kwargs: dict,
) -> np.ndarray: ... # np.ndarray[float]
Copy link
Member

Choose a reason for hiding this comment

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

the code starts with

if n == 0:
        return obj

so the return type could be same as obj

Comment on lines 76 to 77
args: tuple,
kwargs: dict,
Copy link
Member

Choose a reason for hiding this comment

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

These are passed to func with no restrictions so I think OK to type as

Suggested change
args: tuple,
kwargs: dict,
args: tuple[Any, ...],
kwargs: dict[str, Any],

to be consistent with _generate_cython_apply_func

self.min_periods,
# error: Argument 4 to "ewmcov" has incompatible type
# "Optional[int]"; expected "int"
self.min_periods, # type: ignore[arg-type]
Copy link
Member

Choose a reason for hiding this comment

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

in the outer scope we have

            min_periods = (
                self.min_periods
                if self.min_periods is not None
                else window_indexer.window_size
            )

can we not just pass min_periods here.

Copy link
Member Author

Choose a reason for hiding this comment

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

cc @mroeschke ?

Copy link
Member

Choose a reason for hiding this comment

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

True; since the EWM constructor always has an numeric min_periods this can just be self.min_periods

@simonjayhawkins
Copy link
Member

Thanks @jbrockmendel lgtm pending green.

@simonjayhawkins simonjayhawkins added this to the 1.3 milestone Apr 27, 2021
@jbrockmendel
Copy link
Member Author

updated + green

@mroeschke mroeschke merged commit dd4418c into pandas-dev:master Apr 28, 2021
@mroeschke
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the typ-window branch April 28, 2021 01:06
yeshsurya pushed a commit to yeshsurya/pandas that referenced this pull request May 6, 2021
* TYP: aggregations.pyx

* update per comments
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
* TYP: aggregations.pyx

* update per comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants