Skip to content

Commit

Permalink
Fix 2 type annotations in dataarray.py (#5548)
Browse files Browse the repository at this point in the history
Both `set_index` and `reset_index` are wrappers to other methods that return `"DataArray"`, not `Optional["DataArray"]`. That is, they will never return None. That's why these methods should also have only `"DataArray"` in there return signature. This way it will be possible to do something like `myarray = myarray.reset_index(...)` without getting a complaint from Mypy.

For extended discussion, see #5533 (comment)
  • Loading branch information
joooeey authored Jun 29, 2021
1 parent 5ccb069 commit c5dbe98
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ def set_index(
indexes: Mapping[Hashable, Union[Hashable, Sequence[Hashable]]] = None,
append: bool = False,
**indexes_kwargs: Union[Hashable, Sequence[Hashable]],
) -> Optional["DataArray"]:
) -> "DataArray":
"""Set DataArray (multi-)indexes using one or more existing
coordinates.
Expand Down Expand Up @@ -1958,7 +1958,7 @@ def reset_index(
self,
dims_or_levels: Union[Hashable, Sequence[Hashable]],
drop: bool = False,
) -> Optional["DataArray"]:
) -> "DataArray":
"""Reset the specified index(es) or multi-index level(s).
Parameters
Expand Down

0 comments on commit c5dbe98

Please sign in to comment.