MCPcopy
hub / github.com/pydata/xarray / test_groupby_math_more

Function test_groupby_math_more

xarray/tests/test_groupby.py:977–1008  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

975
976
977def test_groupby_math_more() -> None:
978 ds = create_test_data()
979 grouped = ds.groupby("numbers")
980 zeros = DataArray([0, 0, 0, 0], [("numbers", range(4))])
981 expected = (ds + Variable("dim3", np.zeros(10))).transpose(
982 "dim3", "dim1", "dim2", "time"
983 )
984 actual = grouped + zeros
985 assert_equal(expected, actual)
986
987 actual = zeros + grouped
988 assert_equal(expected, actual)
989
990 with pytest.raises(ValueError, match=r"incompat.* grouped binary"):
991 grouped + ds
992 with pytest.raises(ValueError, match=r"incompat.* grouped binary"):
993 ds + grouped
994 with pytest.raises(TypeError, match=r"only support binary ops"):
995 grouped + 1 # type: ignore[operator]
996 with pytest.raises(TypeError, match=r"only support binary ops"):
997 grouped + grouped # type: ignore[operator]
998 with pytest.raises(TypeError, match=r"in-place operations"):
999 ds += grouped # type: ignore[arg-type]
1000
1001 ds = Dataset(
1002 {
1003 "x": ("time", np.arange(100)),
1004 "time": pd.date_range("2000-01-01", periods=100),
1005 }
1006 )
1007 with pytest.raises(ValueError, match=r"incompat.* grouped binary"):
1008 ds + ds.groupby("time.month")
1009
1010
1011def test_groupby_math_bitshift() -> None:

Callers

nothing calls this directly

Calls 8

groupbyMethod · 0.95
create_test_dataFunction · 0.90
DataArrayClass · 0.90
VariableClass · 0.90
assert_equalFunction · 0.90
DatasetClass · 0.90
arangeMethod · 0.80
transposeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…