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

Method test_stacking_stacked

xarray/tests/test_units.py:3636–3660  ·  view source on GitHub ↗
(self, func, dtype)

Source from the content-addressed store, hash-verified

3634 ids=repr,
3635 )
3636 def test_stacking_stacked(self, func, dtype):
3637 array = (
3638 np.linspace(0, 10, 5 * 10).reshape(5, 10).astype(dtype) * unit_registry.m
3639 )
3640 x = np.arange(array.shape[0])
3641 y = np.arange(array.shape[1])
3642
3643 data_array = xr.DataArray(
3644 name="data", data=array, coords={"x": x, "y": y}, dims=("x", "y")
3645 )
3646 stacked = data_array.stack(z=("x", "y"))
3647
3648 expected = attach_units(func(strip_units(stacked)), {"data": unit_registry.m})
3649 actual = func(stacked)
3650
3651 assert_units_equal(expected, actual)
3652 # TODO: strip_units/attach_units reconstruct DataArrays from scratch,
3653 # losing index structure (e.g., MultiIndex from stack becomes regular Index).
3654 # Fix these utilities to preserve indexes, then remove check_indexes=False.
3655 if func.name == "reset_index":
3656 assert_identical(
3657 expected, actual, check_default_indexes=False, check_indexes=False
3658 )
3659 else:
3660 assert_identical(expected, actual, check_indexes=False)
3661
3662 @pytest.mark.skip(reason="indexes don't support units")
3663 def test_to_unstacked_dataset(self, dtype):

Callers

nothing calls this directly

Calls 9

stackMethod · 0.95
assert_identicalFunction · 0.90
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
arangeMethod · 0.80
funcFunction · 0.70
astypeMethod · 0.45

Tested by

no test coverage detected