diff options
author | Shota Kawabuchi <shota.kawabuchi+Github@gmail.com> | 2016-11-01 23:22:55 +0900 |
---|---|---|
committer | Shota Kawabuchi <shota.kawabuchi+Github@gmail.com> | 2016-11-01 23:22:55 +0900 |
commit | e1326c31526a607cc981b309a3a092b1cbbc9b9c (patch) | |
tree | a5b9421040d22384e08a18dff80ecaeef1a1a6b8 /numpy/core/arrayprint.py | |
parent | a6c2184c0dbc70b9a57fce21e4f769d313021261 (diff) | |
download | numpy-e1326c31526a607cc981b309a3a092b1cbbc9b9c.tar.gz |
MAINT: Refactor numpy/core/arrayprint.py
Related to PR #8200
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index ce0c6244e..a9fcfcdaa 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -279,10 +279,9 @@ def _get_format_function(data, precision, suppress_small, formatter): format_functions = [] for field_name in dtype_.names: field_values = data[field_name] - is_array_field = 1 < field_values.ndim format_function = _get_format_function( ravel(field_values), precision, suppress_small, formatter) - if is_array_field: + if dtype_[field_name].shape != (): format_function = SubArrayFormat(format_function) format_functions.append(format_function) return StructureFormat(format_functions) @@ -337,17 +336,6 @@ def _array2string(a, max_line_width, precision, suppress_small, separator=' ', _summaryEdgeItems, summary_insert)[:-1] return lst -def _convert_arrays(obj): - from . import numeric as _nc - newtup = [] - for k in obj: - if isinstance(k, _nc.ndarray): - k = k.tolist() - elif isinstance(k, tuple): - k = _convert_arrays(k) - newtup.append(k) - return tuple(newtup) - def array2string(a, max_line_width=None, precision=None, suppress_small=None, separator=' ', prefix="", @@ -461,7 +449,7 @@ def array2string(a, max_line_width=None, precision=None, if a.shape == (): x = a.item() if a.dtype.fields is not None: - arr = asarray([x], dtype=a.dtype) + arr = array([x], dtype=a.dtype) format_function = _get_format_function( arr, precision, suppress_small, formatter) lst = format_function(arr[0]) @@ -494,10 +482,7 @@ def _formatArray(a, format_function, rank, max_line_len, """ if rank == 0: - obj = a.item() - if isinstance(obj, tuple): - obj = _convert_arrays(obj) - return str(obj) + raise ValueError("rank shouldn't be zero.") if summary_insert and 2*edge_items < len(a): leading_items = edge_items |