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

Method test_getitem_1d_fancy

xarray/tests/test_variable.py:126–144  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

124 assert_array_equal(v_new, data)
125
126 def test_getitem_1d_fancy(self):
127 v = self.cls(["x"], [0, 1, 2])
128 # 1d-variable should be indexable by multi-dimensional Variable
129 ind = Variable(("a", "b"), [[0, 1], [0, 1]])
130 v_new = v[ind]
131 assert v_new.dims == ("a", "b")
132 expected = np.array(v._data)[([0, 1], [0, 1]), ...]
133 assert_array_equal(v_new, expected)
134
135 # boolean indexing
136 ind = Variable(("x",), [True, False, True])
137 v_new = v[ind]
138 assert_identical(v[[0, 2]], v_new)
139 v_new = v[[True, False, True]]
140 assert_identical(v[[0, 2]], v_new)
141
142 with pytest.raises(IndexError, match=r"Boolean indexer should"):
143 ind = Variable(("a",), [True, False, True])
144 v[ind]
145
146 def test_getitem_with_mask(self):
147 v = self.cls(["x"], [0, 1, 2])

Callers

nothing calls this directly

Calls 3

VariableClass · 0.90
assert_identicalFunction · 0.90
clsMethod · 0.45

Tested by

no test coverage detected