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

Function construct_dataarray

xarray/tests/test_duck_array_ops.py:373–402  ·  view source on GitHub ↗
(dim_num, dtype, contains_nan, dask)

Source from the content-addressed store, hash-verified

371
372
373def construct_dataarray(dim_num, dtype, contains_nan, dask):
374 # dimnum <= 3
375 rng = np.random.default_rng(0)
376 shapes = [16, 8, 4][:dim_num]
377 dims = ("x", "y", "z")[:dim_num]
378
379 if np.issubdtype(dtype, np.floating):
380 array = rng.random(shapes).astype(dtype)
381 elif np.issubdtype(dtype, np.integer):
382 array = rng.integers(0, 10, size=shapes).astype(dtype)
383 elif np.issubdtype(dtype, np.bool_):
384 array = rng.integers(0, 1, size=shapes).astype(dtype)
385 elif dtype is str:
386 array = rng.choice(["a", "b", "c", "d"], size=shapes)
387 else:
388 raise ValueError
389
390 if contains_nan:
391 inds = rng.choice(range(array.size), int(array.size * 0.2))
392 dtype, fill_value = dtypes.maybe_promote(array.dtype)
393 array = array.astype(dtype)
394 array.flat[inds] = fill_value
395
396 da = DataArray(array, dims=dims, coords={"x": np.arange(16)}, name="da")
397
398 if dask and has_dask:
399 chunks = dict.fromkeys(dims, 4)
400 da = da.chunk(chunks)
401
402 return da
403
404
405def from_series_or_scalar(se):

Callers 8

test_reduceFunction · 0.85
test_argmin_maxFunction · 0.85
test_argmin_max_errorFunction · 0.85
test_isnull_with_daskFunction · 0.85
test_min_countFunction · 0.85
test_min_count_ndFunction · 0.85
test_min_count_datasetFunction · 0.85
test_multiple_dimsFunction · 0.85

Calls 4

chunkMethod · 0.95
DataArrayClass · 0.90
arangeMethod · 0.80
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…