summaryrefslogtreecommitdiff
path: root/numpy/core/arrayprint.py
diff options
context:
space:
mode:
authorPan Jan <rumcajsgajos@gmail.com>2020-04-17 09:10:26 +0200
committerPan Jan <rumcajsgajos@gmail.com>2020-04-17 09:10:26 +0200
commita95aae3acac02e9c8b17e9cb3e460c26e2eba0ae (patch)
tree027b2ae190ba250d28e3218f67a79014cbcf43d7 /numpy/core/arrayprint.py
parent947b6a6380c08b02047beb4c34466c6d2bdc9ffe (diff)
downloadnumpy-a95aae3acac02e9c8b17e9cb3e460c26e2eba0ae.tar.gz
Improve way of breaking lines
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r--numpy/core/arrayprint.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index 01db605f6..0f3e5ea5c 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -710,20 +710,27 @@ def _extendLine_pretty(s, line, word, line_width, next_line_prefix, legacy):
"""
Extends line with nicely formatted (possibly multi-line) string ``word``.
"""
- if legacy == '1.13':
+ words = word.splitlines()
+ if len(words) == 1 or legacy == '1.13':
return _extendLine(s, line, word, line_width, next_line_prefix, legacy)
- words = word.splitlines()
line_length = len(line)
- s, line = _extendLine(
- s, line, words[0], line_width, next_line_prefix, legacy)
+ max_word_length = max(len(word) for word in words)
+ if line_length + max_word_length > line_width and \
+ len(line) > len(next_line_prefix):
+ s += line.rstrip() + '\n'
+ line = next_line_prefix + words[0]
+ indent = next_line_prefix
+ else:
+ line += words[0]
+ indent = line_length*' '
+
for word in words[1::]:
s += line.rstrip() + '\n'
- if line_length + len(word) > line_width \
- and line_length > len(next_line_prefix):
- line = next_line_prefix + word
- else:
- line = line_length*' ' + word
+ line = indent + word
+
+ suffix_length = max_word_length-len(words[-1])
+ line += suffix_length*' '
return s, line