(self, func, variant, dtype, compute_backend)
| 5447 | ), |
| 5448 | ) |
| 5449 | def test_grouped_operations(self, func, variant, dtype, compute_backend): |
| 5450 | variants = { |
| 5451 | "data": ((unit_registry.degK, unit_registry.Pa), 1, 1), |
| 5452 | "dims": ((1, 1), unit_registry.m, 1), |
| 5453 | "coords": ((1, 1), 1, unit_registry.m), |
| 5454 | } |
| 5455 | (unit1, unit2), dim_unit, coord_unit = variants[variant] |
| 5456 | |
| 5457 | array1 = np.linspace(-5, 5, 5 * 4).reshape(5, 4).astype(dtype) * unit1 |
| 5458 | array2 = np.linspace(10, 20, 5 * 4 * 3).reshape(5, 4, 3).astype(dtype) * unit2 |
| 5459 | x = np.arange(5) * dim_unit |
| 5460 | y = np.arange(4) * dim_unit |
| 5461 | z = np.arange(3) * dim_unit |
| 5462 | |
| 5463 | u = np.linspace(-1, 0, 4) * coord_unit |
| 5464 | |
| 5465 | ds = xr.Dataset( |
| 5466 | data_vars={"a": (("x", "y"), array1), "b": (("x", "y", "z"), array2)}, |
| 5467 | coords={"x": x, "y": y, "z": z, "u": ("y", u)}, |
| 5468 | ) |
| 5469 | |
| 5470 | assigned_units = {"c": unit2, "v": unit_registry.s} |
| 5471 | units = merge_mappings(extract_units(ds), assigned_units) |
| 5472 | |
| 5473 | stripped_kwargs = { |
| 5474 | name: strip_units(value) for name, value in func.kwargs.items() |
| 5475 | } |
| 5476 | expected = attach_units( |
| 5477 | func(strip_units(ds).groupby("y", squeeze=False), **stripped_kwargs), units |
| 5478 | ) |
| 5479 | actual = func(ds.groupby("y", squeeze=False)) |
| 5480 | |
| 5481 | assert_units_equal(expected, actual) |
| 5482 | assert_equal(expected, actual) |
| 5483 | |
| 5484 | @pytest.mark.parametrize( |
| 5485 | "func", |
nothing calls this directly
no test coverage detected