Skip to content

Commit

Permalink
And `DataWithCoords
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Sep 20, 2023
1 parent 2f357d3 commit 1aa3286
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
DatetimeLike,
DTypeLikeSave,
ScalarOrArray,
Self,
SideOptions,
T_Chunks,
T_DataWithCoords,
Expand Down Expand Up @@ -381,11 +382,11 @@ class DataWithCoords(AttrAccessMixin):
__slots__ = ("_close",)

def squeeze(
self: T_DataWithCoords,
self,
dim: Hashable | Iterable[Hashable] | None = None,
drop: bool = False,
axis: int | Iterable[int] | None = None,
) -> T_DataWithCoords:
) -> Self:
"""Return a new object with squeezed data.
Parameters
Expand Down Expand Up @@ -414,12 +415,12 @@ def squeeze(
return self.isel(drop=drop, **{d: 0 for d in dims})

def clip(
self: T_DataWithCoords,
self,
min: ScalarOrArray | None = None,
max: ScalarOrArray | None = None,
*,
keep_attrs: bool | None = None,
) -> T_DataWithCoords:
) -> Self:
"""
Return an array whose values are limited to ``[min, max]``.
At least one of max or min must be given.
Expand Down Expand Up @@ -472,10 +473,10 @@ def _calc_assign_results(
return {k: v(self) if callable(v) else v for k, v in kwargs.items()}

def assign_coords(
self: T_DataWithCoords,
self,
coords: Mapping[Any, Any] | None = None,
**coords_kwargs: Any,
) -> T_DataWithCoords:
) -> Self:
"""Assign new coordinates to this object.
Returns a new object with all the original data in addition to the new
Expand Down Expand Up @@ -620,9 +621,7 @@ def assign_coords(
data.coords.update(results)
return data

def assign_attrs(
self: T_DataWithCoords, *args: Any, **kwargs: Any
) -> T_DataWithCoords:
def assign_attrs(self, *args: Any, **kwargs: Any) -> Self:
"""Assign new attrs to this object.
Returns a new object equivalent to ``self.attrs.update(*args, **kwargs)``.
Expand Down Expand Up @@ -1061,9 +1060,7 @@ def _resample(
restore_coord_dims=restore_coord_dims,
)

def where(
self: T_DataWithCoords, cond: Any, other: Any = dtypes.NA, drop: bool = False
) -> T_DataWithCoords:
def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self:
"""Filter elements from this object according to a condition.
This operation follows the normal broadcasting and alignment rules that
Expand Down Expand Up @@ -1205,9 +1202,7 @@ def close(self) -> None:
self._close()
self._close = None

def isnull(
self: T_DataWithCoords, keep_attrs: bool | None = None
) -> T_DataWithCoords:
def isnull(self, keep_attrs: bool | None = None) -> Self:
"""Test each value in the array for whether it is a missing value.
Parameters
Expand Down Expand Up @@ -1250,9 +1245,7 @@ def isnull(
keep_attrs=keep_attrs,
)

def notnull(
self: T_DataWithCoords, keep_attrs: bool | None = None
) -> T_DataWithCoords:
def notnull(self, keep_attrs: bool | None = None) -> Self:
"""Test each value in the array for whether it is not a missing value.
Parameters
Expand Down Expand Up @@ -1295,7 +1288,7 @@ def notnull(
keep_attrs=keep_attrs,
)

def isin(self: T_DataWithCoords, test_elements: Any) -> T_DataWithCoords:
def isin(self, test_elements: Any) -> Self:
"""Tests each value in the array for whether it is in test elements.
Parameters
Expand Down Expand Up @@ -1344,15 +1337,15 @@ def isin(self: T_DataWithCoords, test_elements: Any) -> T_DataWithCoords:
)

def astype(
self: T_DataWithCoords,
self,
dtype,
*,
order=None,
casting=None,
subok=None,
copy=None,
keep_attrs=True,
) -> T_DataWithCoords:
) -> Self:
"""
Copy of the xarray object, with data cast to a specified type.
Leaves coordinate dtype unchanged.
Expand Down Expand Up @@ -1419,7 +1412,7 @@ def astype(
dask="allowed",
)

def __enter__(self: T_DataWithCoords) -> T_DataWithCoords:
def __enter__(self) -> Self:
return self

def __exit__(self, exc_type, exc_value, traceback) -> None:
Expand Down

0 comments on commit 1aa3286

Please sign in to comment.