-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
TYP: some types for pandas/core/arrays/sparse/array.py #29898
Conversation
pandas/core/arrays/sparse/array.py
Outdated
@@ -372,8 +375,11 @@ def __init__( | |||
|
|||
@classmethod | |||
def _simple_new( | |||
cls, sparse_array: np.ndarray, sparse_index: SparseIndex, dtype: SparseDtype | |||
) -> ABCSparseArray: | |||
cls: Type[_SparseArrayT], |
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.
needing to annotate cls
seems weird. is that just me?
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.
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.
pandas/core/arrays/sparse/array.py
Outdated
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 |
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 saying anything about contents?
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 until _take_with_fill and _take_without_fill are annotated. removed till then.
pandas/core/arrays/sparse/array.py
Outdated
def sparse_unary_method(self): | ||
def _create_unary_method( | ||
cls: Type[_SparseArrayT], op | ||
) -> Callable[[_SparseArrayT], _SparseArrayT]: |
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.
does mypy specifically need this? my kneejerk reaction is that it adds verbosity but not clarity
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 could see how far we get without it. but remember your frustration with subclass of ChainMap not returning the same type?
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 case I haven't mentioned it recently, I'm totally happy to defer to you when it comes to annotations
small comments, non-blockers, LGTM |
Thanks @simonjayhawkins |
broken off #28339