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

Method test_groupby_bins_multidim

xarray/tests/test_groupby.py:1801–1827  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1799 assert len(array.x) == 4
1800
1801 def test_groupby_bins_multidim(self) -> None:
1802 array = self.make_groupby_multidim_example_array()
1803 bins = [0, 15, 20]
1804 bin_coords = pd.cut(array["lat"].values.flat, bins).categories # type: ignore[call-overload]
1805 expected = DataArray([16, 40], dims="lat_bins", coords={"lat_bins": bin_coords})
1806 actual = array.groupby_bins("lat", bins).map(lambda x: x.sum())
1807 assert_identical(expected, actual)
1808 # modify the array coordinates to be non-monotonic after unstacking
1809 array["lat"].data = np.array([[10.0, 20.0], [20.0, 10.0]])
1810 expected = DataArray([28, 28], dims="lat_bins", coords={"lat_bins": bin_coords})
1811 actual = array.groupby_bins("lat", bins).map(lambda x: x.sum())
1812 assert_identical(expected, actual)
1813
1814 bins = [-2, -1, 0, 1, 2]
1815 field = DataArray(np.ones((5, 3)), dims=("x", "y"))
1816 by = DataArray(
1817 np.array([[-1.5, -1.5, 0.5, 1.5, 1.5] * 3]).reshape(5, 3), dims=("x", "y")
1818 )
1819 actual = field.groupby_bins(by, bins=bins).count()
1820
1821 bincoord = pd.IntervalIndex.from_breaks(bins, closed="right")
1822 expected = DataArray(
1823 np.array([6, np.nan, 3, 6]),
1824 dims="group_bins",
1825 coords={"group_bins": bincoord},
1826 )
1827 assert_identical(actual, expected)
1828
1829 def test_groupby_bins_sort(self) -> None:
1830 data = xr.DataArray(

Callers

nothing calls this directly

Calls 8

groupby_binsMethod · 0.95
DataArrayClass · 0.90
assert_identicalFunction · 0.90
mapMethod · 0.45
groupby_binsMethod · 0.45
sumMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected