Skip to content

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

Merged
merged 13 commits into from
Oct 25, 2019
Merged

Conversation

jbrockmendel
Copy link
Member

No description provided.

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.

lgtm

@@ -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))
Copy link
Member

Choose a reason for hiding this comment

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

closes #27676

Copy link
Member

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

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Oct 23, 2019
@simonjayhawkins simonjayhawkins added this to the 1.0 milestone Oct 23, 2019


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.
Copy link
Contributor

Choose a reason for hiding this comment

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

iff -> if

Copy link
Member Author

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]):
Copy link
Contributor

Choose a reason for hiding this comment

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

should be = None then

Copy link
Member Author

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

Copy link
Contributor

@jreback jreback left a 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.

Copy link
Member

@WillAyd WillAyd left a 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,
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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

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

sort: bool = True,
ascending: bool = False,
normalize: bool = False,
bins=None,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bins=None,
bins: Optional[bool] = None,

(unless docstring is wrong)

Copy link
Member Author

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?

Copy link
Member

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

Copy link
Member

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,
):
Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

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

@@ -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))
Copy link
Member

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

@WillAyd WillAyd merged commit 7220659 into pandas-dev:master Oct 25, 2019
@WillAyd
Copy link
Member

WillAyd commented Oct 25, 2019

Great thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the typing branch October 25, 2019 17:35
HawkinsBA pushed a commit to HawkinsBA/pandas that referenced this pull request Oct 29, 2019
Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
bongolegend pushed a commit to bongolegend/pandas that referenced this pull request Jan 1, 2020
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.

4 participants