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

Method test_groupby_bins_empty

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

Source from the content-addressed store, hash-verified

1787 assert_identical(actual, expected)
1788
1789 def test_groupby_bins_empty(self) -> None:
1790 array = DataArray(np.arange(4), [("x", range(4))])
1791 # one of these bins will be empty
1792 bins = [0, 4, 5]
1793 bin_coords = pd.cut(array["x"], bins).categories # type: ignore[call-overload]
1794 actual = array.groupby_bins("x", bins).sum()
1795 expected = DataArray([6, np.nan], dims="x_bins", coords={"x_bins": bin_coords})
1796 assert_identical(expected, actual)
1797 # make sure original array is unchanged
1798 # (was a problem in earlier versions)
1799 assert len(array.x) == 4
1800
1801 def test_groupby_bins_multidim(self) -> None:
1802 array = self.make_groupby_multidim_example_array()

Callers

nothing calls this directly

Calls 5

groupby_binsMethod · 0.95
DataArrayClass · 0.90
assert_identicalFunction · 0.90
arangeMethod · 0.80
sumMethod · 0.45

Tested by

no test coverage detected