(self, func, unit, error, dtype)
| 1589 | ), |
| 1590 | ) |
| 1591 | def test_numpy_methods(self, func, unit, error, dtype): |
| 1592 | array = np.linspace(0, 1, 10).astype(dtype) * unit_registry.m |
| 1593 | variable = xr.Variable("x", array) |
| 1594 | |
| 1595 | args = [ |
| 1596 | item * unit if isinstance(item, int | float | list) else item |
| 1597 | for item in func.args |
| 1598 | ] |
| 1599 | kwargs = { |
| 1600 | key: value * unit if isinstance(value, int | float | list) else value |
| 1601 | for key, value in func.kwargs.items() |
| 1602 | } |
| 1603 | |
| 1604 | if error is not None and func.name in ("searchsorted", "clip"): |
| 1605 | with pytest.raises(error): |
| 1606 | func(variable, *args, **kwargs) |
| 1607 | |
| 1608 | return |
| 1609 | |
| 1610 | converted_args = [ |
| 1611 | strip_units(convert_units(item, {None: unit_registry.m})) for item in args |
| 1612 | ] |
| 1613 | converted_kwargs = { |
| 1614 | key: strip_units(convert_units(value, {None: unit_registry.m})) |
| 1615 | for key, value in kwargs.items() |
| 1616 | } |
| 1617 | |
| 1618 | units = extract_units(func(array, *args, **kwargs)) |
| 1619 | expected = attach_units( |
| 1620 | func(strip_units(variable), *converted_args, **converted_kwargs), units |
| 1621 | ) |
| 1622 | actual = func(variable, *args, **kwargs) |
| 1623 | |
| 1624 | assert_units_equal(expected, actual) |
| 1625 | assert_allclose(expected, actual) |
| 1626 | |
| 1627 | @pytest.mark.parametrize( |
| 1628 | "func", (method("item", 5), method("searchsorted", 5)), ids=repr |
nothing calls this directly
no test coverage detected