|
16 | 16 | TypeVar,
|
17 | 17 | Union,
|
18 | 18 | cast,
|
19 |
| - overload, |
20 | 19 | )
|
21 | 20 |
|
22 | 21 | import numpy as np
|
|
53 | 52 | from .formatting import format_item
|
54 | 53 | from .indexes import Indexes, default_indexes
|
55 | 54 | from .options import OPTIONS
|
56 |
| -from .utils import Default, ReprObject, _default, _check_inplace, either_dict_or_kwargs |
| 55 | +from .utils import Default, ReprObject, _check_inplace, _default, either_dict_or_kwargs |
57 | 56 | from .variable import (
|
58 | 57 | IndexVariable,
|
59 | 58 | Variable,
|
@@ -249,7 +248,7 @@ class DataArray(AbstractArray, DataWithCoords):
|
249 | 248 | Dictionary for holding arbitrary metadata.
|
250 | 249 | """
|
251 | 250 |
|
252 |
| - _accessors: Optional[Dict[str, Any]] |
| 251 | + _accessors: Optional[Dict[str, Any]] # noqa |
253 | 252 | _coords: Dict[Any, Variable]
|
254 | 253 | _indexes: Optional[Dict[Hashable, pd.Index]]
|
255 | 254 | _name: Optional[Hashable]
|
@@ -1890,41 +1889,72 @@ def transpose(self, *dims: Hashable, transpose_coords: bool = None) -> "DataArra
|
1890 | 1889 | def T(self) -> "DataArray":
|
1891 | 1890 | return self.transpose()
|
1892 | 1891 |
|
1893 |
| - # Drop coords |
1894 |
| - @overload |
1895 |
| - def drop( |
1896 |
| - self, labels: Union[Hashable, Iterable[Hashable]], *, errors: str = "raise" |
| 1892 | + def drop_vars( |
| 1893 | + self, names: Union[Hashable, Iterable[Hashable]], *, errors: str = "raise" |
1897 | 1894 | ) -> "DataArray":
|
1898 |
| - ... |
| 1895 | + """Drop variables from this DataArray. |
| 1896 | +
|
| 1897 | + Parameters |
| 1898 | + ---------- |
| 1899 | + names : hashable or iterable of hashables |
| 1900 | + Name(s) of variables to drop. |
| 1901 | + errors: {'raise', 'ignore'}, optional |
| 1902 | + If 'raise' (default), raises a ValueError error if any of the variable |
| 1903 | + passed are not in the dataset. If 'ignore', any given names that are in the |
| 1904 | + DataArray are dropped and no error is raised. |
| 1905 | +
|
| 1906 | + Returns |
| 1907 | + ------- |
| 1908 | + dropped : Dataset |
| 1909 | +
|
| 1910 | + """ |
| 1911 | + ds = self._to_temp_dataset().drop_vars(names, errors=errors) |
| 1912 | + return self._from_temp_dataset(ds) |
1899 | 1913 |
|
1900 |
| - # Drop index labels along dimension |
1901 |
| - @overload # noqa: F811 |
1902 | 1914 | def drop(
|
1903 |
| - self, labels: Any, dim: Hashable, *, errors: str = "raise" # array-like |
| 1915 | + self, |
| 1916 | + labels: Mapping = None, |
| 1917 | + dim: Hashable = None, |
| 1918 | + *, |
| 1919 | + errors: str = "raise", |
| 1920 | + **labels_kwargs, |
1904 | 1921 | ) -> "DataArray":
|
1905 |
| - ... |
| 1922 | + """Backward compatible method based on `drop_vars` and `drop_sel` |
1906 | 1923 |
|
1907 |
| - def drop(self, labels, dim=None, *, errors="raise"): # noqa: F811 |
1908 |
| - """Drop coordinates or index labels from this DataArray. |
| 1924 | + Using either `drop_vars` or `drop_sel` is encouraged |
| 1925 | + """ |
| 1926 | + ds = self._to_temp_dataset().drop(labels, dim, errors=errors) |
| 1927 | + return self._from_temp_dataset(ds) |
| 1928 | + |
| 1929 | + def drop_sel( |
| 1930 | + self, |
| 1931 | + labels: Mapping[Hashable, Any] = None, |
| 1932 | + *, |
| 1933 | + errors: str = "raise", |
| 1934 | + **labels_kwargs, |
| 1935 | + ) -> "DataArray": |
| 1936 | + """Drop index labels from this DataArray. |
1909 | 1937 |
|
1910 | 1938 | Parameters
|
1911 | 1939 | ----------
|
1912 |
| - labels : hashable or sequence of hashables |
1913 |
| - Name(s) of coordinates or index labels to drop. |
1914 |
| - If dim is not None, labels can be any array-like. |
1915 |
| - dim : hashable, optional |
1916 |
| - Dimension along which to drop index labels. By default (if |
1917 |
| - ``dim is None``), drops coordinates rather than index labels. |
| 1940 | + labels : Mapping[Hashable, Any] |
| 1941 | + Index labels to drop |
1918 | 1942 | errors: {'raise', 'ignore'}, optional
|
1919 | 1943 | If 'raise' (default), raises a ValueError error if
|
1920 |
| - any of the coordinates or index labels passed are not |
1921 |
| - in the array. If 'ignore', any given labels that are in the |
1922 |
| - array are dropped and no error is raised. |
| 1944 | + any of the index labels passed are not |
| 1945 | + in the dataset. If 'ignore', any given labels that are in the |
| 1946 | + dataset are dropped and no error is raised. |
| 1947 | + **labels_kwargs : {dim: label, ...}, optional |
| 1948 | + The keyword arguments form of ``dim`` and ``labels`` |
| 1949 | +
|
1923 | 1950 | Returns
|
1924 | 1951 | -------
|
1925 | 1952 | dropped : DataArray
|
1926 | 1953 | """
|
1927 |
| - ds = self._to_temp_dataset().drop(labels, dim, errors=errors) |
| 1954 | + if labels_kwargs or isinstance(labels, dict): |
| 1955 | + labels = either_dict_or_kwargs(labels, labels_kwargs, "drop") |
| 1956 | + |
| 1957 | + ds = self._to_temp_dataset().drop_sel(labels, errors=errors) |
1928 | 1958 | return self._from_temp_dataset(ds)
|
1929 | 1959 |
|
1930 | 1960 | def dropna(
|
|
0 commit comments