-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Add types in a handful of places #29178
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
Conversation
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.
lgtm
pandas/io/excel/_odfreader.py
Outdated
@@ -60,7 +61,7 @@ def get_sheet_by_name(self, name: str): | |||
if table.getAttribute("name") == name: | |||
return table | |||
|
|||
raise ValueError("sheet {name} not found".format(name)) | |||
raise ValueError("sheet {name} not found".format(name=name)) |
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.
closes #27676
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 is being address in #27677 with more detail (i.e. tests) so would rather revert here and let that PR take care of it, especially since it is their first contribution
pandas/core/nanops.py
Outdated
|
||
|
||
def _maybe_get_mask( | ||
values: np.ndarray, skipna: bool, mask: Optional[np.ndarray] | ||
) -> Optional[np.ndarray]: | ||
""" This function will compute a mask iff it is necessary. Otherwise, | ||
""" | ||
Compute a mask iff necessary. |
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.
iff -> if
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.
iff --> "if and only if"
else: | ||
result = result.astype("m8[ns]").view(dtype) | ||
|
||
return result | ||
|
||
|
||
def _na_for_min_count(values, axis): | ||
"""Return the missing value for `values` | ||
def _na_for_min_count(values, axis: Optional[int]): |
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 = None then
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.
we're requiring the caller to pass something though
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.
minor comment, ping on green.
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.
Looks pretty good. For the parts of the signature that you left unannotated - is the reason for that simply that they are too complex to decipher in a quick pass?
@@ -692,30 +692,34 @@ def factorize(values, sort=False, order=None, na_sentinel=-1, size_hint=None): | |||
|
|||
|
|||
def value_counts( | |||
values, sort=True, ascending=False, normalize=False, bins=None, dropna=True | |||
values, |
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.
Can type this as ndarray I think
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.
the name = getattr(values, "name", None)
suggests that it could be a Series or Index
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.
Do you think AnyArrayLike
from pandas._typing is applicable here?
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.
im hoping to refactor such that this function (as many as possible in this module, really) doesn't handle Series or Index so prefer not to make this official
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.
Sounds good
sort: bool = True, | ||
ascending: bool = False, | ||
normalize: bool = False, | ||
bins=None, |
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.
bins=None, | |
bins: Optional[bool] = None, |
(unless docstring is wrong)
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.
docstring says int. should it be bool?
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.
No this is a typo on my end
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.
Meant Optional[int] though? Can do in a follow up
ascending: bool = False, | ||
normalize: bool = False, | ||
bins=None, | ||
dropna: bool = True, | ||
): |
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.
You can annotate return as "Series". Not sure it will type check but still helpful I think
@@ -1340,7 +1340,7 @@ def _intersection_non_unique(self, other: "IntervalIndex") -> "IntervalIndex": | |||
|
|||
return self[mask] | |||
|
|||
def _setop(op_name, sort=None): | |||
def _setop(op_name: str, sort=None): |
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.
Was going to suggest annotating sort
but looks like unused? Maybe delete altogether?
Can annotate the return here at least as Callable
would be helpful too (better with subscripting if not too much effort). At first glance I assume setop
meant that this set some value and wouldn't return anything, but looks not to be the case
result_shape = values.shape[:axis] + values.shape[axis + 1 :] | ||
result = np.empty(result_shape, dtype=values.dtype) | ||
result.fill(fill_value) | ||
return result | ||
|
||
|
||
def nanany(values, axis=None, skipna=True, mask=None): | ||
def nanany(values, axis=None, skipna: bool = True, mask=None): |
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.
Not sure if applicable here but you could use the Axis
definition from pandas._typing, if this can accept both integers and "index"/"columns"
Annotated bool
return value for this and below would be great too
pandas/io/excel/_odfreader.py
Outdated
@@ -60,7 +61,7 @@ def get_sheet_by_name(self, name: str): | |||
if table.getAttribute("name") == name: | |||
return table | |||
|
|||
raise ValueError("sheet {name} not found".format(name)) | |||
raise ValueError("sheet {name} not found".format(name=name)) |
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 is being address in #27677 with more detail (i.e. tests) so would rather revert here and let that PR take care of it, especially since it is their first contribution
Great thanks @jbrockmendel |
No description provided.