(self, func, variant, dtype)
| 5517 | ), |
| 5518 | ) |
| 5519 | def test_content_manipulation(self, func, variant, dtype): |
| 5520 | variants = { |
| 5521 | "data": ( |
| 5522 | (unit_registry.m**3, unit_registry.Pa, unit_registry.degK), |
| 5523 | 1, |
| 5524 | 1, |
| 5525 | ), |
| 5526 | "dims": ((1, 1, 1), unit_registry.m, 1), |
| 5527 | "coords": ((1, 1, 1), 1, unit_registry.m), |
| 5528 | } |
| 5529 | (unit1, unit2, unit3), dim_unit, coord_unit = variants[variant] |
| 5530 | |
| 5531 | array1 = np.linspace(-5, 5, 5 * 4).reshape(5, 4).astype(dtype) * unit1 |
| 5532 | array2 = np.linspace(10, 20, 5 * 4 * 3).reshape(5, 4, 3).astype(dtype) * unit2 |
| 5533 | array3 = np.linspace(0, 10, 5).astype(dtype) * unit3 |
| 5534 | |
| 5535 | x = np.arange(5) * dim_unit |
| 5536 | y = np.arange(4) * dim_unit |
| 5537 | z = np.arange(3) * dim_unit |
| 5538 | |
| 5539 | x2 = np.linspace(-1, 0, 5) * coord_unit |
| 5540 | |
| 5541 | ds = xr.Dataset( |
| 5542 | data_vars={ |
| 5543 | "a": (("x", "y"), array1), |
| 5544 | "b": (("x", "y", "z"), array2), |
| 5545 | "c": ("x", array3), |
| 5546 | }, |
| 5547 | coords={"x": x, "y": y, "z": z, "x2": ("x", x2)}, |
| 5548 | ) |
| 5549 | |
| 5550 | new_units = { |
| 5551 | "y2": unit_registry.mm, |
| 5552 | "x_mm": coord_unit, |
| 5553 | "offset_x": unit_registry.m, |
| 5554 | "d": unit2, |
| 5555 | "temperature": unit3, |
| 5556 | } |
| 5557 | units = merge_mappings(extract_units(ds), new_units) |
| 5558 | |
| 5559 | stripped_kwargs = { |
| 5560 | key: strip_units(value) for key, value in func.kwargs.items() |
| 5561 | } |
| 5562 | expected = attach_units(func(strip_units(ds), **stripped_kwargs), units) |
| 5563 | actual = func(ds) |
| 5564 | |
| 5565 | assert_units_equal(expected, actual) |
| 5566 | if func.name == "rename_dims": |
| 5567 | assert_equal(expected, actual, check_default_indexes=False) |
| 5568 | else: |
| 5569 | assert_equal(expected, actual) |
| 5570 | |
| 5571 | @pytest.mark.parametrize( |
| 5572 | "unit,error", |
nothing calls this directly
no test coverage detected