Skip to content

TYP: some types for pandas/core/arrays/sparse/array.py #29898

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

Conversation

simonjayhawkins
Copy link
Member

broken off #28339

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Nov 27, 2019
@@ -372,8 +375,11 @@ def __init__(

@classmethod
def _simple_new(
cls, sparse_array: np.ndarray, sparse_index: SparseIndex, dtype: SparseDtype
) -> ABCSparseArray:
cls: Type[_SparseArrayT],
Copy link
Member

Choose a reason for hiding this comment

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

needing to annotate cls seems weird. is that just me?

Copy link
Member Author

Choose a reason for hiding this comment

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

annotated for generic self. see https://mypy.readthedocs.io/en/latest/generics.html#generic-methods-and-generic-self

again could see how far we get without this.

if is_scalar(indices):
raise ValueError(
"'indices' must be an array, not a scalar '{}'.".format(indices)
)
indices = np.asarray(indices, dtype=np.int32)

result: List
Copy link
Member

Choose a reason for hiding this comment

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

not saying anything about contents?

Copy link
Member Author

Choose a reason for hiding this comment

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

not until _take_with_fill and _take_without_fill are annotated. removed till then.

def sparse_unary_method(self):
def _create_unary_method(
cls: Type[_SparseArrayT], op
) -> Callable[[_SparseArrayT], _SparseArrayT]:
Copy link
Member

Choose a reason for hiding this comment

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

does mypy specifically need this? my kneejerk reaction is that it adds verbosity but not clarity

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 could see how far we get without it. but remember your frustration with subclass of ChainMap not returning the same 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 case I haven't mentioned it recently, I'm totally happy to defer to you when it comes to annotations

@jbrockmendel
Copy link
Member

small comments, non-blockers, LGTM

@simonjayhawkins simonjayhawkins added this to the 1.0 milestone Nov 27, 2019
@WillAyd WillAyd merged commit 69ef543 into pandas-dev:master Nov 29, 2019
@WillAyd
Copy link
Member

WillAyd commented Nov 29, 2019

Thanks @simonjayhawkins

@simonjayhawkins simonjayhawkins deleted the pandas/core/arrays/sparse/array.py branch December 1, 2019 13:21
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
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