8000 MAINT: Cleanup `ma.array.__str__` by eric-wieser · Pull Request #9768 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Cleanup ma.array.__str__ #9768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MAINT: Remove special casing of 0d in MaskedArray.__str__
  • Loading branch information
eric-wieser committed Sep 25, 2017
commit 91b83ac6a9477bfb469e270b6e8634b597a3d1ac
27 changes: 5 additions & 22 deletions numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3827,30 +3827,13 @@ def __str__(self):

"""
if masked_print_option.enabled():
f = masked_print_option
if self is masked:
return str(f)
m = self._mask
if m is nomask:
mask = self._mask
if mask is nomask:
res = self._data
else:
if m.shape == () and m.itemsize==len(m.dtype):
if m.dtype.names:
m = m.view((bool, len(m.dtype)))
if m.any():
return str(tuple((f if _m else _d) for _d, _m in
zip(self._data.tolist(), m)))
else:
return str(self._data)
elif m:
return str(f)
else:
return str(self._data)
# convert to object array to make filled work
names = self.dtype.names
if names is None:
if self.dtype.names is None:
data = self._data
mask = m
# For big arrays, to avoid a costly conversion to the
# object dtype, extract the corners before the conversion.
print_width = (self._print_width if self.ndim > 1
Expand All @@ -3863,11 +3846,11 @@ def __str__(self):
arr = np.split(mask, (ind, -ind), axis=axis)
mask = np.concatenate((arr[0], arr[2]), axis=axis)
res = data.astype("O")
res.view(ndarray)[mask] = f
res.view(ndarray)[mask] = masked_print_option
else:
rdtype = _replace_dtype_fields(self.dtype, "O")
res = self._data.astype(rdtype)
_recursive_printoption(res, m, f)
_recursive_printoption(res, mask, masked_print_option)
else:
res = self.filled(self.fill_value)
return str(res)
Expand Down
0