Skip to content
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

Fix typing #96

Closed
dcherian opened this issue May 10, 2022 · 2 comments · Fixed by #150
Closed

Fix typing #96

dcherian opened this issue May 10, 2022 · 2 comments · Fixed by #150
Labels
help wanted Extra attention is needed

Comments

@dcherian
Copy link
Collaborator

There are a bunch of errors if I run mypy in flox/

A lot seem easy and some seem like bugs =)

flox/core.py:69: error: Value of type "Optional[Any]" is not indexable  [index]
flox/core.py:69: error: Argument "isbin" to "_convert_expected_groups_to_index" has incompatible type "Tuple[bool]"; expected "bool"  [arg-type]
flox/core.py:447: error: Value of type "Optional[ndarray[Any, Any]]" is not indexable  [index]
flox/core.py:550: error: Incompatible default for argument "axis" (default has type "None", argument has type "Union[int, Sequence[int]]")  [assignment]
flox/core.py:605: error: Incompatible types in assignment (expression has type "Tuple[None]", variable has type "Optional[Mapping[Union[str, Callable[..., Any]], Any]]")  [assignment]
flox/core.py:661: error: No overload variant of "zip" matches argument types "Union[Sequence[str], Sequence[Callable[..., Any]]]", "None", "Any", "Any"  [call-overload]
flox/core.py:661: note: Possible overload variants:
flox/core.py:661: note:     def [_T_co, _T1] zip(cls, Iterable[_T1]) -> zip[Tuple[_T1]]
flox/core.py:661: note:     def [_T_co, _T1, _T2] zip(cls, Iterable[_T1], Iterable[_T2]) -> zip[Tuple[_T1, _T2]]
flox/core.py:661: note:     def [_T_co, _T1, _T2, _T3] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3]) -> zip[Tuple[_T1, _T2, _T3]]
flox/core.py:661: note:     def [_T_co, _T1, _T2, _T3, _T4] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], Iterable[_T4]) -> zip[Tuple[_T1, _T2, _T3, _T4]]
flox/core.py:661: note:     def [_T_co, _T1, _T2, _T3, _T4, _T5] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], Iterable[_T4], Iterable[_T5]) -> zip[Tuple[_T1, _T2, _T3, _T4, _T5]]
flox/core.py:661: note:     def [_T_co] zip(cls, Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], *iterables: Iterable[Any]) -> zip[Tuple[Any, ...]]
flox/core.py:665: error: Argument 1 to "is_nanlen" has incompatible type "None"; expected "Union[str, Callable[..., Any]]"  [arg-type]
flox/core.py:802: error: Unsupported left operand type for + ("Sequence[Any]")  [operator]
flox/core.py:804: error: Unsupported left operand type for + ("Sequence[Any]")  [operator]
flox/core.py:809: error: Incompatible return value type (got "Dict[str, Any]", expected "Dict[Union[str, Callable[..., Any]], Any]")  [return-value]
flox/core.py:809: note: Perhaps you need a type annotation for "results"? Suggestion: "Dict[Union[str, Callable[..., Any]], Any]"
flox/core.py:895: error: Incompatible types in assignment (expression has type "Dict[Union[str, Callable[..., Any]], Any]", variable has type "Dict[str, object]")  [assignment]
flox/core.py:911: error: "object" has no attribute "append"  [attr-defined]
flox/core.py:914: error: "object" has no attribute "append"  [attr-defined]
flox/core.py:921: error: Argument "fill_value" to "chunk_reduce" has incompatible type "Tuple[int]"; expected "Optional[Mapping[Union[str, Callable[..., Any]], Any]]"  [arg-type]
flox/core.py:937: error: "object" has no attribute "append"  [attr-defined]
flox/core.py:950: error: Argument "fill_value" to "chunk_reduce" has incompatible type "Tuple[Any]"; expected "Optional[Mapping[Union[str, Callable[..., Any]], Any]]"  [arg-type]
flox/core.py:955: error: "object" has no attribute "append"  [attr-defined]
flox/core.py:957: error: Incompatible return value type (got "Dict[str, object]", expected "Dict[Union[str, Callable[..., Any]], Any]")  [return-value]
flox/core.py:957: note: Perhaps you need a type annotation for "results"? Suggestion: "Dict[Union[str, Callable[..., Any]], Any]"
flox/core.py:1175: error: Argument 1 to "partial" has incompatible type "object"; expected "Callable[..., <nothing>]"  [arg-type]
flox/core.py:1228: error: Item "None" of "Optional[Any]" has no attribute "values"  [union-attr]
flox/core.py:1290: error: No overload variant of "zip" matches argument types "Tuple[Any, ...]", "bool"  [call-overload]
flox/core.py:1290: note: Possible overload variants:
flox/core.py:1290: note:     def [_T_co, _T1] zip(cls, Iterable[_T1]) -> zip[Tuple[_T1]]
flox/core.py:1290: note:     def [_T_co, _T1, _T2] zip(cls, Iterable[_T1], Iterable[_T2]) -> zip[Tuple[_T1, _T2]]
flox/core.py:1290: note:     def [_T_co, _T1, _T2, _T3] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3]) -> zip[Tuple[_T1, _T2, _T3]]
flox/core.py:1290: note:     def [_T_co, _T1, _T2, _T3, _T4] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], Iterable[_T4]) -> zip[Tuple[_T1, _T2, _T3, _T4]]
flox/core.py:1290: note:     def [_T_co, _T1, _T2, _T3, _T4, _T5] zip(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], Iterable[_T4], Iterable[_T5]) -> zip[Tuple[_T1, _T2, _T3, _T4, _T5]]
flox/core.py:1290: note:     def [_T_co] zip(cls, Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], *iterables: Iterable[Any]) -> zip[Tuple[Any, ...]]
flox/core.py:1457: error: Argument 1 to "_validate_reindex" has incompatible type "Optional[bool]"; expected "bool"  [arg-type]
flox/core.py:1465: error: Incompatible types in assignment (expression has type "Tuple[bool, ...]", variable has type "bool")  [assignment]
flox/core.py:1478: error: Argument 1 to "_convert_expected_groups_to_index" has incompatible type "Union[Tuple[None, ...], Sequence[Any], ndarray[Any, Any]]"; expected "Tuple[Any, ...]"  [arg-type]
flox/core.py:1490: error: Value of type "Optional[Any]" is not indexable  [index]
flox/core.py:1543: error: Argument 4 to "_initialize_aggregation" has incompatible type "Optional[int]"; expected "int"  [arg-type]
flox/core.py:1567: error: Item "ndarray[Any, Any]" of "Union[ndarray[Any, Any], Any]" has no attribute "chunks"  [union-attr]
flox/core.py:1580: error: Item "ndarray[Any, Any]" of "Union[ndarray[Any, Any], Any]" has no attribute "chunks"  [union-attr]
flox/core.py:1608: error: Incompatible types in assignment (expression has type "List[Union[ndarray[Any, Any], Any]]", variable has type "Tuple[Any]")  [assignment]
flox/xarray.py:19: error: Module "xarray" has no attribute "Resample"  [attr-defined]
flox/xarray.py:231: error: Unsupported right operand type for in ("Optional[Hashable]")  [operator]
flox/xarray.py:237: error: "Hashable" has no attribute "__iter__" (not iterable)  [attr-defined]
flox/xarray.py:240: error: "Hashable" has no attribute "__iter__" (not iterable)  [attr-defined]
flox/xarray.py:248: error: Incompatible types in assignment (expression has type "Union[str, Aggregation]", variable has type "str")  [assignment]
flox/xarray.py:256: error: Argument 1 to "len" has incompatible type "Hashable"; expected "Sized"  [arg-type]
flox/xarray.py:277: error: Argument 1 to "_convert_expected_groups_to_index" has incompatible type "List[Any]"; expected "Tuple[Any, ...]"  [arg-type]
flox/xarray.py:277: error: Argument 2 to "_convert_expected_groups_to_index" has incompatible type "Sequence[bool]"; expected "bool"  [arg-type]
flox/xarray.py:278: error: Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "List[None]")  [assignment]
flox/xarray.py:278: error: Item "None" of "Optional[Any]" has no attribute "__iter__" (not iterable)  [union-attr]
flox/xarray.py:301: error: "Hashable" has no attribute "__iter__" (not iterable)  [attr-defined]
flox/xarray.py:314: error: Argument 1 to "set" has incompatible type "Hashable"; expected "Iterable[Any]"  [arg-type]
flox/xarray.py:330: error: Argument 1 to "tuple" has incompatible type "Optional[Any]"; expected "Iterable[Any]"  [arg-type]
flox/xarray.py:339: error: "Hashable" has no attribute "__iter__" (not iterable)  [attr-defined]
flox/xarray.py:342: error: Argument 2 to "zip" has incompatible type "Optional[Any]"; expected "Iterable[Any]"  [arg-type]
flox/visualize.py:4: error: Skipping analyzing "matplotlib": module is installed, but missing library stubs or py.typed marker  [import]
flox/visualize.py:5: error: Skipping analyzing "matplotlib.pyplot": module is installed, but missing library stubs or py.typed marker  [import]

Originally posted by @dcherian in #92 (comment)

@dcherian dcherian added the help wanted Extra attention is needed label May 10, 2022
@dcherian dcherian pinned this issue May 10, 2022
@headtr1ck
Copy link

While at it:
The dim argument to xarray_reduce should be str | Iterable[Hashable] | Ellipsis | None

@dcherian
Copy link
Collaborator Author

PRs welcome! ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants