MCPcopy Create free account
hub / github.com/dask/dask / test_histogram2d

Function test_histogram2d

dask/array/tests/test_routines.py:947–974  ·  view source on GitHub ↗
(weights, density, bins)

Source from the content-addressed store, hash-verified

945@pytest.mark.parametrize("density", [True, False])
946@pytest.mark.parametrize("bins", [(5, 6), 5])
947def test_histogram2d(weights, density, bins):
948 rng = da.random.default_rng()
949 n = 800
950 b = bins
951 r = ((0, 1), (0, 1))
952 x = rng.uniform(0, 1, size=(n,), chunks=(200,))
953 y = rng.uniform(0, 1, size=(n,), chunks=(200,))
954 w = rng.uniform(0.2, 1.1, size=(n,), chunks=(200,)) if weights else None
955 a1, b1x, b1y = da.histogram2d(x, y, bins=b, range=r, density=density, weights=w)
956 a2, b2x, b2y = np.histogram2d(x, y, bins=b, range=r, density=density, weights=w)
957 a3, b3x, b3y = np.histogram2d(
958 x.compute(),
959 y.compute(),
960 bins=b,
961 range=r,
962 density=density,
963 weights=w.compute() if weights else None,
964 )
965 assert_eq(a1, a2)
966 assert_eq(a1, a3)
967 if not (weights or density):
968 assert a1.sum() == n
969 assert a2.sum() == n
970 assert same_keys(
971 da.histogram2d(x, y, bins=b, range=r, density=density, weights=w)[0],
972 a1,
973 )
974 assert a1.compute().shape == a3.shape
975
976
977@pytest.mark.parametrize("weights", [True, False])

Callers

nothing calls this directly

Calls 5

assert_eqFunction · 0.90
same_keysFunction · 0.90
uniformMethod · 0.45
computeMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected