8000 MAINT: Remove special casing of structured dtypes in MaskedArray.__str__ · numpy/numpy@25c808c · GitHub
[go: up one dir, main page]

Skip to content

Commit 25c808c

Browse files
committed
MAINT: Remove special casing of structured dtypes in MaskedArray.__str__
This means that large void arrays are now truncated as they are for other types, for speed.
1 parent 91b83ac commit 25c808c

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

numpy/ma/core.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,12 +2418,13 @@ def _recursive_printoption(result, mask, printopt):
24182418
24192419
"""
24202420
names = result.dtype.names
2421-
for name in names:
2422-
(curdata, curmask) = (result[name], mask[name])
2423-
if result.dtype[name].names:
2421+
if na 8000 mes:
2422+
for name in names:
2423+
curdata = result[name]
2424+
curmask = mask[name]
24242425
_recursive_printoption(curdata, curmask, printopt)
2425-
else:
2426-
np.copyto(curdata, printopt, where=curmask)
2426+
else:
2427+
np.copyto(result, printopt, where=mask)
24272428
return
24282429

24292430
_print_templates = dict(long_std="""\
@@ -3832,25 +3833,22 @@ def __str__(self):
38323833
res = self._data
38333834
else:
38343835
# convert to object array to make filled work
3835-
if self.dtype.names is None:
3836-
data = self._data
3837-
# For big arrays, to avoid a costly conversion to the
3838-
# object dtype, extract the corners before the conversion.
3839-
print_width = (self._print_width if self.ndim > 1
3840-
else self._print_width_1d)
3841-
for axis in range(self.ndim):
3842-
if data.shape[axis] > print_width:
3843-
ind = print_width // 2
3844-
arr = np.split(data, (ind, -ind), axis=axis)
3845-
data = np.concatenate((arr[0], arr[2]), axis=axis)
3846-
arr = np.split(mask, (ind, -ind), axis=axis)
3847-
mask = np.concatenate((arr[0], arr[2]), axis=axis)
3848-
res = data.astype("O")
3849-
res.view(ndarray)[mask] = masked_print_option
3850-
else:
3851-
rdtype = _replace_dtype_fields(self.dtype, "O")
3852-
res = self._data.astype(rdtype)
3853-
_recursive_printoption(res, mask, masked_print_option)
3836+
data = self._data
3837+
# For big arrays, to avoid a costly conversion to the
3838+
# object dtype, extract the corners before the conversion.
3839+
print_width = (self._print_width if self.ndim > 1
3840+
else self._print_width_1d)
3841+
for axis in range(self.ndim):
3842+
if data.shape[axis] > print_width:
3843+
ind = print_width // 2
3844+
arr = np.split(data, (ind, -ind), axis=axis)
3845+
data = np.concatenate((arr[0], arr[2]), axis=axis)
3846+
arr = np.split(mask, (ind, -ind), axis=axis)
3847+
mask = np.concatenate((arr[0], arr[2]), axis=axis)
3848+
3849+
rdtype = _replace_dtype_fields(self.dtype, "O")
3850+
res = data.astype(rdtype)
3851+
_recursive_printoption(res, mask, masked_print_option)
38543852
else:
38553853
res = self.filled(self.fill_value)
38563854
return str(res)

0 commit comments

Comments
 (0)
0