From 2ecae5ee158b9600c207b4c42e2ed531c8f385e9 Mon Sep 17 00:00:00 2001 From: Allan Haldane Date: Thu, 14 Sep 2017 10:58:15 -0400 Subject: MAINT: rework recursive guard to keep array2string signature --- numpy/core/arrayprint.py | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'numpy/core/arrayprint.py') diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 795ceec6c..cdcf94007 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -349,30 +349,6 @@ def _get_format_function(data, precision, suppress_small, formatter): else: return formatdict['numpystr']() -def _array2string(a, max_line_width, precision, suppress_small, separator=' ', - prefix="", formatter=None): - - if a.size > _summaryThreshold: - summary_insert = "..., " - data = _leading_trailing(a) - else: - summary_insert = "" - data = ravel(asarray(a)) - - # find the right formatting function for the array - format_function = _get_format_function(data, precision, - suppress_small, formatter) - - # skip over "[" - next_line_prefix = " " - # skip over array( - next_line_prefix += " "*len(prefix) - - lst = _formatArray(a, format_function, a.ndim, max_line_width, - next_line_prefix, separator, - _summaryEdgeItems, summary_insert)[:-1] - return lst - def _recursive_guard(fillvalue='...'): """ @@ -403,9 +379,33 @@ def _recursive_guard(fillvalue='...'): return decorating_function -# gracefully handle recursive calls - this comes up when object arrays contain -# themselves +# gracefully handle recursive calls, when object arrays contain themselves @_recursive_guard() +def _array2string(a, max_line_width, precision, suppress_small, separator=' ', + prefix="", formatter=None): + + if a.size > _summaryThreshold: + summary_insert = "..., " + data = _leading_trailing(a) + else: + summary_insert = "" + data = ravel(asarray(a)) + + # find the right formatting function for the array + format_function = _get_format_function(data, precision, + suppress_small, formatter) + + # skip over "[" + next_line_prefix = " " + # skip over array( + next_line_prefix += " "*len(prefix) + + lst = _formatArray(a, format_function, a.ndim, max_line_width, + next_line_prefix, separator, + _summaryEdgeItems, summary_insert)[:-1] + return lst + + def array2string(a, max_line_width=None, precision=None, suppress_small=None, separator=' ', prefix="", style=np._NoValue, formatter=None): @@ -503,7 +503,6 @@ def array2string(a, max_line_width=None, precision=None, '[0x0L 0x1L 0x2L]' """ - # Deprecation 05-16-2017 v1.14 if style is not np._NoValue: warnings.warn("'style' argument is deprecated and no longer functional", -- cgit v1.2.1