(self, func, unit, error, dtype)
| 1971 | "func", (method("where"), method("_getitem_with_mask")), ids=repr |
| 1972 | ) |
| 1973 | def test_masking(self, func, unit, error, dtype): |
| 1974 | base_unit = unit_registry.m |
| 1975 | array = np.linspace(0, 5, 10).astype(dtype) * base_unit |
| 1976 | variable = xr.Variable("x", array) |
| 1977 | cond = np.array([True, False] * 5) |
| 1978 | |
| 1979 | other = -1 * unit |
| 1980 | |
| 1981 | if error is not None: |
| 1982 | with pytest.raises(error): |
| 1983 | func(variable, cond, other) |
| 1984 | |
| 1985 | return |
| 1986 | |
| 1987 | expected = attach_units( |
| 1988 | func( |
| 1989 | strip_units(variable), |
| 1990 | cond, |
| 1991 | strip_units( |
| 1992 | convert_units( |
| 1993 | other, |
| 1994 | ( |
| 1995 | {None: base_unit} |
| 1996 | if is_compatible(base_unit, unit) |
| 1997 | else {None: None} |
| 1998 | ), |
| 1999 | ) |
| 2000 | ), |
| 2001 | ), |
| 2002 | extract_units(variable), |
| 2003 | ) |
| 2004 | actual = func(variable, cond, other) |
| 2005 | |
| 2006 | assert_units_equal(expected, actual) |
| 2007 | assert_identical(expected, actual) |
| 2008 | |
| 2009 | @pytest.mark.parametrize("dim", ("x", "y", "z", "t", "all")) |
| 2010 | def test_squeeze(self, dim, dtype): |
nothing calls this directly
no test coverage detected