Skip to content

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

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