3030from .merge import merge_attrs , merge_coordinates_without_align
3131from .options import OPTIONS , _get_keep_attrs
3232from .pycompat import is_duck_dask_array
33+ from .types import T_DataArray
3334from .utils import is_dict_like
3435from .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 )
0 commit comments