(self, func, unit, error, dtype)
| 1640 | ), |
| 1641 | ) |
| 1642 | def test_raw_numpy_methods(self, func, unit, error, dtype): |
| 1643 | array = np.linspace(0, 1, 10).astype(dtype) * unit_registry.m |
| 1644 | variable = xr.Variable("x", array) |
| 1645 | |
| 1646 | args = [ |
| 1647 | ( |
| 1648 | item * unit |
| 1649 | if isinstance(item, int | float | list) and func.name != "item" |
| 1650 | else item |
| 1651 | ) |
| 1652 | for item in func.args |
| 1653 | ] |
| 1654 | kwargs = { |
| 1655 | key: ( |
| 1656 | value * unit |
| 1657 | if isinstance(value, int | float | list) and func.name != "item" |
| 1658 | else value |
| 1659 | ) |
| 1660 | for key, value in func.kwargs.items() |
| 1661 | } |
| 1662 | |
| 1663 | if error is not None and func.name != "item": |
| 1664 | with pytest.raises(error): |
| 1665 | func(variable, *args, **kwargs) |
| 1666 | |
| 1667 | return |
| 1668 | |
| 1669 | converted_args = [ |
| 1670 | ( |
| 1671 | strip_units(convert_units(item, {None: unit_registry.m})) |
| 1672 | if func.name != "item" |
| 1673 | else item |
| 1674 | ) |
| 1675 | for item in args |
| 1676 | ] |
| 1677 | converted_kwargs = { |
| 1678 | key: ( |
| 1679 | strip_units(convert_units(value, {None: unit_registry.m})) |
| 1680 | if func.name != "item" |
| 1681 | else value |
| 1682 | ) |
| 1683 | for key, value in kwargs.items() |
| 1684 | } |
| 1685 | |
| 1686 | units = extract_units(func(array, *args, **kwargs)) |
| 1687 | expected = attach_units( |
| 1688 | func(strip_units(variable), *converted_args, **converted_kwargs), units |
| 1689 | ) |
| 1690 | actual = func(variable, *args, **kwargs) |
| 1691 | |
| 1692 | assert_units_equal(expected, actual) |
| 1693 | assert_duckarray_allclose(expected, actual) |
| 1694 | |
| 1695 | @pytest.mark.parametrize( |
| 1696 | "func", (method("isnull"), method("notnull"), method("count")), ids=repr |
nothing calls this directly
no test coverage detected