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

Method test_reduce

xarray/tests/test_variable.py:1863–1887  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1861 v += 1
1862
1863 def test_reduce(self):
1864 v = Variable(["x", "y"], self.d, {"ignored": "attributes"})
1865 # Reduce keeps attrs by default
1866 expected = Variable(["y"], self.d.std(axis=0), {"ignored": "attributes"})
1867 assert_identical(v.reduce(np.std, "x"), expected)
1868 assert_identical(v.reduce(np.std, axis=0), v.reduce(np.std, dim="x"))
1869 assert_identical(
1870 v.reduce(np.std, ["y", "x"]),
1871 Variable([], self.d.std(axis=(0, 1)), {"ignored": "attributes"}),
1872 )
1873 assert_identical(
1874 v.reduce(np.std), Variable([], self.d.std(), {"ignored": "attributes"})
1875 )
1876 # Chained reductions both keep attrs
1877 expected_chained = Variable(
1878 [], self.d.mean(axis=0).std(), {"ignored": "attributes"}
1879 )
1880 assert_identical(
1881 v.reduce(np.mean, "x").reduce(np.std, "y"),
1882 expected_chained,
1883 )
1884 assert_allclose(v.mean("x"), v.reduce(np.mean, "x"))
1885
1886 with pytest.raises(ValueError, match=r"cannot supply both"):
1887 v.mean(dim="x", axis=0)
1888
1889 @requires_bottleneck
1890 @pytest.mark.parametrize("compute_backend", ["bottleneck"], indirect=True)

Callers

nothing calls this directly

Calls 7

reduceMethod · 0.95
VariableClass · 0.90
assert_identicalFunction · 0.90
assert_allcloseFunction · 0.90
stdMethod · 0.45
meanMethod · 0.45
reduceMethod · 0.45

Tested by

no test coverage detected