Recursively produce a fill value for `dtype`, calling f on scalar dtypes
(dtype, f)
| 197 | del float_types_list |
| 198 | |
| 199 | def _recursive_fill_value(dtype, f): |
| 200 | """ |
| 201 | Recursively produce a fill value for `dtype`, calling f on scalar dtypes |
| 202 | """ |
| 203 | if dtype.names is not None: |
| 204 | # We wrap into `array` here, which ensures we use NumPy cast rules |
| 205 | # for integer casts, this allows the use of 99999 as a fill value |
| 206 | # for int8. |
| 207 | # TODO: This is probably a mess, but should best preserve behavior? |
| 208 | vals = tuple( |
| 209 | np.array(_recursive_fill_value(dtype[name], f)) |
| 210 | for name in dtype.names) |
| 211 | return np.array(vals, dtype=dtype)[()] # decay to void scalar from 0d |
| 212 | elif dtype.subdtype: |
| 213 | subtype, shape = dtype.subdtype |
| 214 | subval = _recursive_fill_value(subtype, f) |
| 215 | return np.full(shape, subval) |
| 216 | else: |
| 217 | return f(dtype) |
| 218 | |
| 219 | |
| 220 | def _get_dtype_of(obj): |
no test coverage detected