MCPcopy
hub / github.com/numpy/numpy / _recursive_fill_value

Function _recursive_fill_value

numpy/ma/core.py:218–247  ·  view source on GitHub ↗

Recursively produce a fill value for `dtype`, calling f on scalar dtypes

(dtype, f)

Source from the content-addressed store, hash-verified

216del float_types_list
217
218def _recursive_fill_value(dtype, f):
219 """
220 Recursively produce a fill value for `dtype`, calling f on scalar dtypes
221 """
222 if dtype.names is not None:
223 # We wrap into `array` here, which ensures we use NumPy cast rules
224 # for integer casts, this allows the use of 99999 as a fill value
225 # for int8.
226 vals = []
227 for name in dtype.names:
228 field_dtype = dtype[name]
229 val = _recursive_fill_value(field_dtype, f)
230 if np.issubdtype(field_dtype, np.datetime64):
231 if isinstance(val, dt.date):
232 val = np.datetime64(val)
233 val = np.array(val)
234 elif isinstance(val, (int, np.integer)):
235 val = np.array(val).astype(field_dtype)
236 else:
237 val = np.array(val)
238 else:
239 val = np.array(val)
240 vals.append(val)
241 return np.array(tuple(vals), dtype=dtype)[()] # decay to void scalar from 0d
242 elif dtype.subdtype:
243 subtype, shape = dtype.subdtype
244 subval = _recursive_fill_value(subtype, f)
245 return np.full(shape, subval)
246 else:
247 return f(dtype)
248
249
250def _get_dtype_of(obj):

Callers 2

default_fill_valueFunction · 0.85
_extremum_fill_valueFunction · 0.85

Calls 2

astypeMethod · 0.80
fFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…