From 607a9275f7bf43fa8548c743d966b939b57cb06c Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Thu, 26 May 2022 18:57:53 -0700 Subject: [PATCH] Adjust code comments & types from #6638 (#6642) --- xarray/core/computation.py | 11 +++++++---- xarray/core/dataarray.py | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 1ca63ff369e..ad1f937a4d0 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -30,6 +30,7 @@ from .merge import merge_attrs, merge_coordinates_without_align from .options import OPTIONS, _get_keep_attrs from .pycompat import is_duck_dask_array +from .types import T_DataArray from .utils import is_dict_like from .variable import Variable @@ -1371,7 +1372,9 @@ def corr(da_a, da_b, dim=None): return _cov_corr(da_a, da_b, dim=dim, method="corr") -def _cov_corr(da_a, da_b, dim=None, ddof=0, method=None): +def _cov_corr( + da_a: T_DataArray, da_b: T_DataArray, dim=None, ddof=0, method=None +) -> T_DataArray: """ Internal method for xr.cov() and xr.corr() so only have to sanitize the input arrays once and we don't repeat code. @@ -1390,9 +1393,9 @@ def _cov_corr(da_a, da_b, dim=None, ddof=0, method=None): demeaned_da_b = da_b - da_b.mean(dim=dim) # 4. Compute covariance along the given dim - # N.B. `skipna=False` is required or there is a bug when computing - # auto-covariance. E.g. Try xr.cov(da,da) for - # da = xr.DataArray([[1, 2], [1, np.nan]], dims=["x", "time"]) + # + # N.B. `skipna=True` is required or auto-covariance is computed incorrectly. E.g. + # Try xr.cov(da,da) for da = xr.DataArray([[1, 2], [1, np.nan]], dims=["x", "time"]) cov = (demeaned_da_a * demeaned_da_b).sum(dim=dim, skipna=True, min_count=1) / ( valid_count ) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index f42a7feea5f..204a4669b3d 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -3548,8 +3548,8 @@ def imag(self) -> DataArray: return self._replace(self.variable.imag) def dot( - self, other: DataArray, dims: Hashable | Sequence[Hashable] | None = None - ) -> DataArray: + self, other: T_DataArray, dims: Hashable | Sequence[Hashable] | None = None + ) -> T_DataArray: """Perform dot product of two DataArrays along their shared dims. Equivalent to taking taking tensordot over all shared dims.