-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
TYP: Annotations in pandas/core/nanops.py #30461
Conversation
pandas/core/nanops.py
Outdated
def nancorr( | ||
a: np.ndarray, | ||
b: np.ndarray, | ||
method: str = "pearson", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be Union[str, Callable[...]]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy raises errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then something else is wrong
f12b581
to
bce03ad
Compare
In the CI logs:
For this to work you need to first do |
bce03ad
to
edbc33d
Compare
apparently a test in test_nanops is missing a td.skip_if_no_scipy. have you rebased recently? |
edbc33d
to
422f9a2
Compare
Yes, I have |
pandas/core/nanops.py
Outdated
skipna: bool = True, | ||
min_count: int = 0, | ||
mask: Optional[np.ndarray] = None, | ||
) -> Dtype: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dtype as the return type looks sketchy. are you sure about this?
pandas/core/nanops.py
Outdated
if method in ["kendall", "spearman"]: | ||
def get_corr_func(method) -> Callable: | ||
if method in ["kendall", "spearman", "pearson"]: | ||
from scipy import stats |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the CI issue is that this should be import scipy.stats
3b1f0c7
to
0b6b26f
Compare
pandas/core/nanops.py
Outdated
@@ -1088,18 +1150,14 @@ def nanprod(values, axis=None, skipna=True, min_count=0, mask=None): | |||
|
|||
Returns | |||
------- | |||
result : dtype | |||
The product of all elements on a given axis. ( NaNs are treated as 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be type and then description. same as _maybe_null_out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
looks ok, @MomIsBestFriend there is the return type of nanprod that is incorrect (and not erroring) ? |
On my PC the type is <class 'numpy.float64'> I think that's is because my CPU is 64-bit architecture, should I annotate it as Union[np.float32, np.float64] to add support for 32-bit architecture CPUs as well? |
just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls rebase as well
pandas/core/nanops.py
Outdated
@@ -1240,7 +1307,7 @@ def nancorr(a, b, method="pearson", min_periods=None): | |||
return f(a, b) | |||
|
|||
|
|||
def get_corr_func(method): | |||
def get_corr_func(method) -> Callable: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method: Union[str, Callable]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 7442310 I removed all annotations of str
and Callable
that were added in this PR, it just gave me too much trouble.
This is because no matter what typing annotation combination of "method" is being used "Union[Callable, str]" or "Callable" or "str" mypy is raising errors
Rebased. |
lgtm. @simonjayhawkins or @WillAyd if any comments. let's merge if good rather than add things to this one. ideally we keep basic typing PRs non-controversial and separate out the controversial to other PRs. |
Thanks @MomIsBestFriend |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff