MCPcopy Create free account
hub / github.com/numpy/numpy / _recursive_set_fill_value

Function _recursive_set_fill_value

numpy/ma/core.py:401–430  ·  view source on GitHub ↗

Create a fill value for a structured dtype. Parameters ---------- fillvalue : scalar or array_like Scalar or array representing the fill value. If it is of shorter length than the number of fields in dt, it will be resized. dt : dtype The structured dtyp

(fillvalue, dt)

Source from the content-addressed store, hash-verified

399
400
401def _recursive_set_fill_value(fillvalue, dt):
402 """
403 Create a fill value for a structured dtype.
404
405 Parameters
406 ----------
407 fillvalue : scalar or array_like
408 Scalar or array representing the fill value. If it is of shorter
409 length than the number of fields in dt, it will be resized.
410 dt : dtype
411 The structured dtype for which to create the fill value.
412
413 Returns
414 -------
415 val : tuple
416 A tuple of values corresponding to the structured fill value.
417
418 """
419 fillvalue = np.resize(fillvalue, len(dt.names))
420 output_value = []
421 for (fval, name) in zip(fillvalue, dt.names):
422 cdtype = dt[name]
423 if cdtype.subdtype:
424 cdtype = cdtype.subdtype[0]
425
426 if cdtype.names is not None:
427 output_value.append(tuple(_recursive_set_fill_value(fval, cdtype)))
428 else:
429 output_value.append(np.array(fval, dtype=cdtype).item())
430 return tuple(output_value)
431
432
433def _check_fill_value(fill_value, ndtype):

Callers 1

_check_fill_valueFunction · 0.85

Calls 2

itemMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected