(self, variant, unit, dtype)
| 4650 | ), |
| 4651 | ) |
| 4652 | def test_broadcast_like(self, variant, unit, dtype): |
| 4653 | variants = { |
| 4654 | "data": ((unit_registry.m, unit), (1, 1)), |
| 4655 | "dims": ((1, 1), (unit_registry.m, unit)), |
| 4656 | } |
| 4657 | (data_unit1, data_unit2), (dim_unit1, dim_unit2) = variants[variant] |
| 4658 | |
| 4659 | array1 = np.linspace(1, 2, 2 * 1).reshape(2, 1).astype(dtype) * data_unit1 |
| 4660 | array2 = np.linspace(0, 1, 2 * 3).reshape(2, 3).astype(dtype) * data_unit2 |
| 4661 | |
| 4662 | x1 = np.arange(2) * dim_unit1 |
| 4663 | x2 = np.arange(2) * dim_unit2 |
| 4664 | y1 = np.array([0]) * dim_unit1 |
| 4665 | y2 = np.arange(3) * dim_unit2 |
| 4666 | |
| 4667 | ds1 = xr.Dataset( |
| 4668 | data_vars={"a": (("x", "y"), array1)}, coords={"x": x1, "y": y1} |
| 4669 | ) |
| 4670 | ds2 = xr.Dataset( |
| 4671 | data_vars={"a": (("x", "y"), array2)}, coords={"x": x2, "y": y2} |
| 4672 | ) |
| 4673 | |
| 4674 | expected = attach_units( |
| 4675 | strip_units(ds1).broadcast_like(strip_units(ds2)), extract_units(ds1) |
| 4676 | ) |
| 4677 | actual = ds1.broadcast_like(ds2) |
| 4678 | |
| 4679 | assert_units_equal(expected, actual) |
| 4680 | assert_equal(expected, actual) |
| 4681 | |
| 4682 | @pytest.mark.parametrize( |
| 4683 | "unit", |
nothing calls this directly
no test coverage detected