Repository navigation
MAINT/BUG: Simplify _formatArray, fixing array_repr(matrix) in the process - #10164
Conversation
There was a problem hiding this comment.
Something for another PR - also pass next_line_len = line_len - 2, which solves the problem of np.zeros((1,)*30 + (100,)) being far wider than max_line_len (guarded by legacy)
089cf10 to
55a2fc9
Compare
There was a problem hiding this comment.
All of these cases were simply trying to encode "add a hanging indent, but not on the first line". For 1d cases, we already do that by just adding it, and removing it at the end. Doing the same thing here makes things a lot clearer.
…ocess Now: * Has one recursive base case * Is fewer lines of code * Does not rstrip the result of format_function (none of the builtin ones have trailing spaces anyway) * Recurses in the index, instead of the value, which handles `dtype=object` arrays without the need for the rank argument. This fixes numpy#8442.
55a2fc9 to
d542d14
Compare
|
|
||
| def _extendLine(s, line, word, max_line_len, next_line_prefix): | ||
| if len(line.rstrip()) + len(word.rstrip()) >= max_line_len: | ||
| if len((line + word).rstrip()) > max_line_len: |
There was a problem hiding this comment.
Stripping line made no sense here. We remain compatible by also fixing the comparison, since in practice line had exactly one trailing space (<snip>, ' or <snip> '), except when a custom separator was passed.
mhvk
left a comment
There was a problem hiding this comment.
Looks very nice! Trivial nitpick can be ignored if nobody else has anything
| next_hanging_indent = hanging_indent + ' ' | ||
|
|
||
| a_len = a.shape[axis] | ||
| show_summary = summary_insert and 2*edge_items < a_len |
There was a problem hiding this comment.
Trivial, but while you are at it, could you flip: a_len > 2*edge_items (unless for you that gives cognitive dissonance; for me, one just calculated a_len, so it is obvious it should be compared to something)
| def __rpow__(self, other): | ||
| return NotImplemented | ||
|
|
||
| def __repr__(self): |
There was a problem hiding this comment.
Yay! Lovely to see code disappear.
|
Is this something that should be included in 1.14? |
|
Doesn't really matter of this makes it to 1.14: matrices being broken is not new. Having said that, there are some tweaks to line-wrapping I'd like to make on top of this - namely, actually respecting the max line width. That would belong in 1.14, but probably isn't worth holding up the release for |
|
LGTM. This is the kind of code where tiny details about how exactly a particular space gets added can subtly change the repr in corner cases, making it hard to review thoroughly. But I read the code trying to catch these and it seemed fine, and in my experience the unit tests have been good at catching changes in printing. |
|
I'll try to add some tests |
|
I just meant that the already-existing tests made me more confident, but more tests are always welcome. |
|
My sense would to please try to get all formatting changes in by 1.14 - I really would prefer not to edit doctests for a while!! @eric-wieser - if it helps get the final things in, please just go ahead and merge. |
|
I think Eric isn't working on new tests right now, and I'm not sure we need more. How about we merge in 15 minutes? |
|
That sounds good. Now in 8 minutes I guess. |
|
We'll need the tests for the changes I'm proposing come next anyway (arrays that are one character away from line-wrapping in either direction. But you're correct, I will not be working on this for another 4 hours. |
|
OK, let's merge then. Thanks Eric! |
|
Remaining work is at #10170 |
Final rework of #10123, which in turn reworked #9816.
Now:
dtype=objectarrays without the need for the rank argument. This fixes np.array_repr fails on np.matrix objects #8442 at the same time.