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

Method test_missing_value_fillna

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

Source from the content-addressed store, hash-verified

1728 ),
1729 )
1730 def test_missing_value_fillna(self, unit, error):
1731 value = 10
1732 array = (
1733 np.array(
1734 [
1735 [1.4, 2.3, np.nan, 7.2],
1736 [np.nan, 9.7, np.nan, np.nan],
1737 [2.1, np.nan, np.nan, 4.6],
1738 [9.9, np.nan, 7.2, 9.1],
1739 ]
1740 )
1741 * unit_registry.m
1742 )
1743 variable = xr.Variable(("x", "y"), array)
1744
1745 fill_value = value * unit
1746
1747 if error is not None:
1748 with pytest.raises(error):
1749 variable.fillna(value=fill_value)
1750
1751 return
1752
1753 expected = attach_units(
1754 strip_units(variable).fillna(
1755 value=fill_value.to(unit_registry.m).magnitude
1756 ),
1757 extract_units(variable),
1758 )
1759 actual = variable.fillna(value=fill_value)
1760
1761 assert_units_equal(expected, actual)
1762 assert_identical(expected, actual)
1763
1764 @pytest.mark.parametrize(
1765 "unit",

Callers

nothing calls this directly

Calls 7

fillnaMethod · 0.95
assert_identicalFunction · 0.90
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
extract_unitsFunction · 0.85
assert_units_equalFunction · 0.85
fillnaMethod · 0.45

Tested by

no test coverage detected