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

Function test_min_count_specific

xarray/tests/test_duck_array_ops.py:871–907  ·  view source on GitHub ↗
(dask, func, dim)

Source from the content-addressed store, hash-verified

869@pytest.mark.parametrize("func", ["sum", "prod"])
870@pytest.mark.parametrize("dim", [None, "a", "b"])
871def test_min_count_specific(dask, func, dim):
872 if dask and not has_dask:
873 pytest.skip("requires dask")
874
875 # Simple array with four non-NaN values.
876 da = DataArray(np.ones((6, 6), dtype=np.float64) * np.nan, dims=("a", "b"))
877 da[0][0] = 2
878 da[0][3] = 2
879 da[3][0] = 2
880 da[3][3] = 2
881 if dask:
882 da = da.chunk({"a": 3, "b": 3})
883
884 # Expected result if we set min_count to the number of non-NaNs in a
885 # row/column/the entire array.
886 if dim:
887 min_count = 2
888 expected = DataArray(
889 [4.0, np.nan, np.nan] * 2, dims=("a" if dim == "b" else "b",)
890 )
891 else:
892 min_count = 4
893 expected = DataArray(8.0 if func == "sum" else 16.0)
894
895 # Check for that min_count.
896 with raise_if_dask_computes():
897 actual = getattr(da, func)(dim, skipna=True, min_count=min_count)
898 assert_dask_array(actual, dask)
899 assert_allclose(actual, expected)
900
901 # With min_count being one higher, should get all NaN.
902 min_count += 1
903 expected *= np.nan
904 with raise_if_dask_computes():
905 actual = getattr(da, func)(dim, skipna=True, min_count=min_count)
906 assert_dask_array(actual, dask)
907 assert_allclose(actual, expected)
908
909
910@pytest.mark.parametrize("func", ["sum", "prod"])

Callers

nothing calls this directly

Calls 5

chunkMethod · 0.95
DataArrayClass · 0.90
raise_if_dask_computesFunction · 0.90
assert_allcloseFunction · 0.90
assert_dask_arrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…