MCPcopy Create free account
hub / github.com/pydata/xarray / test_pad_unit_constant_value

Method test_pad_unit_constant_value

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

Source from the content-addressed store, hash-verified

2262 ),
2263 )
2264 def test_pad_unit_constant_value(self, unit, error, dtype):
2265 array = np.linspace(0, 5, 3 * 10).reshape(3, 10).astype(dtype) * unit_registry.m
2266 variable = xr.Variable(("x", "y"), array)
2267
2268 fill_value = -100 * unit
2269
2270 func = method("pad", mode="constant", x=(2, 3), y=(1, 4))
2271 if error is not None:
2272 with pytest.raises(error):
2273 func(variable, constant_values=fill_value)
2274
2275 return
2276
2277 units = extract_units(variable)
2278 expected = attach_units(
2279 func(
2280 strip_units(variable),
2281 constant_values=strip_units(convert_units(fill_value, units)),
2282 ),
2283 units,
2284 )
2285 actual = func(variable, constant_values=fill_value)
2286
2287 assert_units_equal(expected, actual)
2288 assert_identical(expected, actual)
2289
2290
2291class TestDataArray:

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected