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

Function test_groupby_math_bitshift

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

Source from the content-addressed store, hash-verified

1009
1010
1011def test_groupby_math_bitshift() -> None:
1012 # create new dataset of int's only
1013 ds = Dataset(
1014 {
1015 "x": ("index", np.ones(4, dtype=int)),
1016 "y": ("index", np.ones(4, dtype=int) * -1),
1017 "level": ("index", [1, 1, 2, 2]),
1018 "index": [0, 1, 2, 3],
1019 }
1020 )
1021 shift = DataArray([1, 2, 1], [("level", [1, 2, 8])])
1022
1023 left_expected = Dataset(
1024 {
1025 "x": ("index", [2, 2, 4, 4]),
1026 "y": ("index", [-2, -2, -4, -4]),
1027 "level": ("index", [2, 2, 8, 8]),
1028 "index": [0, 1, 2, 3],
1029 }
1030 )
1031
1032 left_manual = []
1033 for lev, group in ds.groupby("level"):
1034 shifter = shift.sel(level=lev)
1035 left_manual.append(group << shifter)
1036 left_actual = xr.concat(left_manual, dim="index").reset_coords(names="level")
1037 assert_equal(left_expected, left_actual)
1038
1039 left_actual = (ds.groupby("level") << shift).reset_coords(names="level")
1040 assert_equal(left_expected, left_actual)
1041
1042 right_expected = Dataset(
1043 {
1044 "x": ("index", [0, 0, 2, 2]),
1045 "y": ("index", [-1, -1, -2, -2]),
1046 "level": ("index", [0, 0, 4, 4]),
1047 "index": [0, 1, 2, 3],
1048 }
1049 )
1050 right_manual = []
1051 for lev, group in left_expected.groupby("level"):
1052 shifter = shift.sel(level=lev)
1053 right_manual.append(group >> shifter)
1054 right_actual = xr.concat(right_manual, dim="index").reset_coords(names="level")
1055 assert_equal(right_expected, right_actual)
1056
1057 right_actual = (left_expected.groupby("level") >> shift).reset_coords(names="level")
1058 assert_equal(right_expected, right_actual)
1059
1060
1061@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 7

groupbyMethod · 0.95
selMethod · 0.95
DatasetClass · 0.90
DataArrayClass · 0.90
assert_equalFunction · 0.90
reset_coordsMethod · 0.45
concatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…