MCPcopy Index your code
hub / github.com/pydata/xarray / test_covcorr_consistency

Function test_covcorr_consistency

xarray/tests/test_computation.py:1711–1727  ·  view source on GitHub ↗
(
    n: int, dim: str | None, array_tuples: tuple[xr.DataArray, xr.DataArray]
)

Source from the content-addressed store, hash-verified

1709@pytest.mark.parametrize("n", range(9))
1710@pytest.mark.parametrize("dim", [None, "time", "x"])
1711def test_covcorr_consistency(
1712 n: int, dim: str | None, array_tuples: tuple[xr.DataArray, xr.DataArray]
1713) -> None:
1714 da_a, da_b = array_tuples[n]
1715 # Testing that xr.corr and xr.cov are consistent with each other
1716 # 1. Broadcast the two arrays
1717 da_a, da_b = broadcast(da_a, da_b)
1718 # 2. Ignore the nans
1719 valid_values = da_a.notnull() & da_b.notnull()
1720 da_a = da_a.where(valid_values)
1721 da_b = da_b.where(valid_values)
1722
1723 expected = xr.cov(da_a, da_b, dim=dim, ddof=0) / (
1724 da_a.std(dim=dim) * da_b.std(dim=dim)
1725 )
1726 actual = xr.corr(da_a, da_b, dim=dim)
1727 assert_allclose(actual, expected)
1728
1729
1730@requires_dask

Callers

nothing calls this directly

Calls 7

broadcastFunction · 0.90
assert_allcloseFunction · 0.90
covMethod · 0.80
corrMethod · 0.80
notnullMethod · 0.45
whereMethod · 0.45
stdMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…