Skip to content

Commit

Permalink
Improve typehints of xr.Dataset.__getitem__
Browse files Browse the repository at this point in the history
Resolves pydata#4125
  • Loading branch information
nbren12 committed Jun 10, 2020
1 parent 2a288f6 commit 34e3ce0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
TypeVar,
Union,
cast,
overload,
)

import numpy as np
Expand Down Expand Up @@ -1240,8 +1241,15 @@ def loc(self) -> _LocIndexer:
and only when the key is a dict of the form {dim: labels}.
"""
return _LocIndexer(self)


def __getitem__(self, key: Any) -> "Union[DataArray, Dataset]":
@overload
def __getitem__(self, key: Hashable) -> DataArray: ...

@overload
def __getitem__(self, key: Any) -> Dataset: ...

def __getitem__(self, key):
"""Access variables or coordinates this dataset as a
:py:class:`~xarray.DataArray`.
Expand Down

0 comments on commit 34e3ce0

Please sign in to comment.