MCPcopy Create free account
hub / github.com/dask/dask / test_creation_functions

Function test_creation_functions

dask/array/tests/test_masked.py:172–219  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

170
171
172def test_creation_functions():
173 x = np.array([-2, -1, 0, 1, 2] * 20).reshape((10, 10))
174 y = np.array([-2, 0, 1, 1, 0] * 2)
175 dx = da.from_array(x, chunks=5)
176 dy = da.from_array(y, chunks=4)
177
178 sol = np.ma.masked_greater(x, y)
179 for a, b in product([dx, x], [dy, y]):
180 assert_eq(da.ma.masked_greater(a, b), sol)
181
182 # These are all the same as masked_greater, just check for correct op
183 assert_eq(da.ma.masked_greater(dx, 0), np.ma.masked_greater(x, 0))
184 assert_eq(da.ma.masked_greater_equal(dx, 0), np.ma.masked_greater_equal(x, 0))
185 assert_eq(da.ma.masked_less(dx, 0), np.ma.masked_less(x, 0))
186 assert_eq(da.ma.masked_less_equal(dx, 0), np.ma.masked_less_equal(x, 0))
187 assert_eq(da.ma.masked_equal(dx, 0), np.ma.masked_equal(x, 0))
188 assert_eq(da.ma.masked_not_equal(dx, 0), np.ma.masked_not_equal(x, 0))
189
190 # masked_where
191 assert_eq(da.ma.masked_where(False, dx), np.ma.masked_where(False, x))
192 assert_eq(da.ma.masked_where(dx > 2, dx), np.ma.masked_where(x > 2, x))
193
194 with pytest.raises(IndexError):
195 da.ma.masked_where((dx > 2)[:, 0], dx)
196
197 assert_eq(da.ma.masked_inside(dx, -1, 1), np.ma.masked_inside(x, -1, 1))
198 assert_eq(da.ma.masked_outside(dx, -1, 1), np.ma.masked_outside(x, -1, 1))
199 assert_eq(da.ma.masked_values(dx, -1), np.ma.masked_values(x, -1))
200
201 # masked_equal and masked_values in numpy sets the fill_value to `value`,
202 # which can sometimes be an array. This is hard to support in dask, so we
203 # forbid it. Check that this isn't supported:
204 with pytest.raises(ValueError):
205 da.ma.masked_equal(dx, dy)
206
207 with pytest.raises(ValueError):
208 da.ma.masked_values(dx, dy)
209
210 y = x.astype("f8")
211 y[0, 0] = y[7, 5] = np.nan
212 dy = da.from_array(y, chunks=5)
213
214 assert_eq(da.ma.masked_invalid(dy), np.ma.masked_invalid(y))
215
216 my = np.ma.masked_greater(y, 0)
217 dmy = da.ma.masked_greater(dy, 0)
218
219 assert_eq(da.ma.fix_invalid(dmy, fill_value=0), np.ma.fix_invalid(my, fill_value=0))
220
221
222def test_filled():

Callers

nothing calls this directly

Calls 3

assert_eqFunction · 0.90
reshapeMethod · 0.80
astypeMethod · 0.45

Tested by

no test coverage detected