30
30
from .merge import merge_attrs , merge_coordinates_without_align
31
31
from .options import OPTIONS , _get_keep_attrs
32
32
from .pycompat import is_duck_dask_array
33
+ from .types import T_DataArray
33
34
from .utils import is_dict_like
34
35
from .variable import Variable
35
36
@@ -1371,7 +1372,9 @@ def corr(da_a, da_b, dim=None):
1371
1372
return _cov_corr (da_a , da_b , dim = dim , method = "corr" )
1372
1373
1373
1374
1374
- def _cov_corr (da_a , da_b , dim = None , ddof = 0 , method = None ):
1375
+ def _cov_corr (
1376
+ da_a : T_DataArray , da_b : T_DataArray , dim = None , ddof = 0 , method = None
1377
+ ) -> T_DataArray :
1375
1378
"""
1376
1379
Internal method for xr.cov() and xr.corr() so only have to
1377
1380
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):
1390
1393
demeaned_da_b = da_b - da_b .mean (dim = dim )
1391
1394
1392
1395
# 4. Compute covariance along the given dim
1393
- # N.B. `skipna=False` is required or there is a bug when computing
1394
- # auto-covariance. E.g. Try xr.cov(da,da) for
1395
- # da = xr.DataArray([[1, 2], [1, np.nan]], dims=["x", "time"])
1396
+ #
1397
+ # N.B. `skipna=True` is required or auto-covariance is computed incorrectly . E.g.
1398
+ # Try xr.cov(da,da) for da = xr.DataArray([[1, 2], [1, np.nan]], dims=["x", "time"])
1396
1399
cov = (demeaned_da_a * demeaned_da_b ).sum (dim = dim , skipna = True , min_count = 1 ) / (
1397
1400
valid_count
1398
1401
)
0 commit comments