summaryrefslogtreecommitdiff
path: root/numpy/ma/core.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2022-10-05 17:45:42 +0200
committerSebastian Berg <sebastianb@nvidia.com>2022-10-05 22:00:56 +0200
commitafcc5608dadb17d7df565f95313cdbc1bd3a399b (patch)
treef560d731514cf5a32731cdd451312f0b1c1f8c11 /numpy/ma/core.py
parent0a821c1c1d46247c29e02570000cc6196ee2884c (diff)
downloadnumpy-afcc5608dadb17d7df565f95313cdbc1bd3a399b.tar.gz
MAINT: Structured MA fill value workaround by adding array cast
This wraps the fill value into an array, the default fill value for all ointegers is 99999 which doesn't work for many integer dtypes. Note that this might still subtle change the behavior in other code paths where we cannot avoid this. Plus, the deprecationwarning may show up (and in fact be a "in the future will use the default fill value" warning).
Diffstat (limited to 'numpy/ma/core.py')
-rw-r--r--numpy/ma/core.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index d3cbb33e5..a2f7c9e5c 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -201,7 +201,13 @@ def _recursive_fill_value(dtype, f):
Recursively produce a fill value for `dtype`, calling f on scalar dtypes
"""
if dtype.names is not None:
- vals = tuple(_recursive_fill_value(dtype[name], f) for name in dtype.names)
+ # We wrap into `array` here, which ensures we use NumPy cast rules
+ # for integer casts, this allows the use of 99999 as a fill value
+ # for int8.
+ # TODO: This is probably a mess, but should best preserve behavior?
+ vals = tuple(
+ np.array(_recursive_fill_value(dtype[name], f))
+ for name in dtype.names)
return np.array(vals, dtype=dtype)[()] # decay to void scalar from 0d
elif dtype.subdtype:
subtype, shape = dtype.subdtype