Skip to content

Commit

Permalink
Adjust code comments & types from #6638 (#6642)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed May 27, 2022
1 parent ab5b162 commit 607a927
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 607a927

Please sign in to comment.