MCPcopy Index your code
hub / github.com/pydata/xarray / test_masking

Method test_masking

xarray/tests/test_units.py:1973–2007  ·  view source on GitHub ↗
(self, func, unit, error, dtype)

Source from the content-addressed store, hash-verified

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):

Callers

nothing calls this directly

Calls 10

assert_identicalFunction · 0.90
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
convert_unitsFunction · 0.85
is_compatibleFunction · 0.85
extract_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
funcFunction · 0.70
astypeMethod · 0.45

Tested by

no test coverage detected