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

More annotations #3177

Merged
merged 9 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ALL_DIMS = ReprObject('<all-dims>')


C = TypeVar('C')
T = TypeVar('T')


Expand Down Expand Up @@ -297,9 +298,11 @@ def get_index(self, key: Hashable) -> pd.Index:
# need to ensure dtype=int64 in case range is empty on Python 2
return pd.Index(range(self.sizes[key]), name=key, dtype=np.int64)

def _calc_assign_results(self, kwargs: Mapping[str, T]
) -> MutableMapping[str, T]:
results = SortedKeysDict() # type: SortedKeysDict[str, T]
def _calc_assign_results(
self: C,
kwargs: Mapping[Hashable, Union[T, Callable[[C], T]]]
) -> MutableMapping[Hashable, T]:
results = SortedKeysDict() # type: SortedKeysDict[Hashable, T]
for k, v in kwargs.items():
if callable(v):
results[k] = v(self)
Expand Down
33 changes: 26 additions & 7 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from collections import OrderedDict
from numbers import Number
from typing import (Any, Callable, Dict, Hashable, Iterable, List, Mapping,
Optional, Sequence, Tuple, Union, cast, TYPE_CHECKING)
Optional, Sequence, Tuple, Union, cast, overload,
TYPE_CHECKING)

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -1752,17 +1753,35 @@ def transpose(self,
def T(self) -> 'DataArray':
return self.transpose()

def drop(self,
labels: Union[Hashable, Sequence[Hashable]],
dim: Hashable = None,
*,
errors: str = 'raise') -> 'DataArray':
# Drop coords
@overload
def drop(
self,
labels: Union[Hashable, Iterable[Hashable]],
*,
errors: str = 'raise'
) -> 'DataArray':
...

# Drop index labels along dimension
@overload # noqa: F811
def drop(
self,
labels: Any, # array-like
dim: Hashable,
*,
errors: str = 'raise'
) -> 'DataArray':
...

def drop(self, labels, dim=None, *, errors='raise'): # noqa: F811
"""Drop coordinates or index labels from this DataArray.

Parameters
----------
labels : hashable or sequence of hashables
Name(s) of coordinate variables or index labels to drop.
Name(s) of coordinates or index labels to drop.
If dim is not None, labels can be any array-like.
dim : hashable, optional
Dimension along which to drop index labels. By default (if
``dim is None``), drops coordinates rather than index labels.
Expand Down
Loading