Skip to content

Commit d4de60a

Browse files
committed
Adjust code comments & types from pydata#6638
1 parent 8de7061 commit d4de60a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

xarray/core/computation.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .merge import merge_attrs, merge_coordinates_without_align
3131
from .options import OPTIONS, _get_keep_attrs
3232
from .pycompat import is_duck_dask_array
33+
from .types import T_DataArray
3334
from .utils import is_dict_like
3435
from .variable import Variable
3536

@@ -1353,7 +1354,9 @@ def corr(da_a, da_b, dim=None):
13531354
return _cov_corr(da_a, da_b, dim=dim, method="corr")
13541355

13551356

1356-
def _cov_corr(da_a, da_b, dim=None, ddof=0, method=None):
1357+
def _cov_corr(
1358+
da_a: T_DataArray, da_b: T_DataArray, dim=None, ddof=0, method=None
1359+
) -> T_DataArray:
13571360
"""
13581361
Internal method for xr.cov() and xr.corr() so only have to
13591362
sanitize the input arrays once and we don't repeat code.
@@ -1372,9 +1375,9 @@ def _cov_corr(da_a, da_b, dim=None, ddof=0, method=None):
13721375
demeaned_da_b = da_b - da_b.mean(dim=dim)
13731376

13741377
# 4. Compute covariance along the given dim
1375-
# N.B. `skipna=False` is required or there is a bug when computing
1376-
# auto-covariance. E.g. Try xr.cov(da,da) for
1377-
# da = xr.DataArray([[1, 2], [1, np.nan]], dims=["x", "time"])
1378+
#
1379+
# N.B. `skipna=True` is required or auto-covariance is computed incorrectly. E.g.
1380+
# Try xr.cov(da,da) for da = xr.DataArray([[1, 2], [1, np.nan]], dims=["x", "time"])
13781381
cov = (demeaned_da_a * demeaned_da_b).sum(dim=dim, skipna=True, min_count=1) / (
13791382
valid_count
13801383
)

xarray/core/dataarray.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,8 +3399,8 @@ def imag(self) -> DataArray:
33993399
return self._replace(self.variable.imag)
34003400

34013401
def dot(
3402-
self, other: DataArray, dims: Hashable | Sequence[Hashable] | None = None
3403-
) -> DataArray:
3402+
self, other: T_DataArray, dims: Hashable | Sequence[Hashable] | None = None
3403+
) -> T_DataArray:
34043404
"""Perform dot product of two DataArrays along their shared dims.
34053405
34063406
Equivalent to taking taking tensordot over all shared dims.

0 commit comments

Comments
 (0)