Repository navigation
BUG: Make np.array_repr work on matrix objects - #10123
eric-wieser wants to merge 3 commits into
Conversation
c2d50bb to
e3390cb
Compare
|
Adding to 1.14 due to the second commit being another repr change. If the rest of this PR holds that up, it can be made stanadalone |
cb2e166 to
5283124
Compare
There was a problem hiding this comment.
Arguably as a result of this change, _leading_trailing didn't need fixing - but the cleanup above seems better anyway.
There was a problem hiding this comment.
I'm actually surprised this wasn't up here before. I would have thought _get_format_function would complain about getting subclasses, and only when the array size was large.
There was a problem hiding this comment.
In order for this to matter, you had to pass an array where size > threshold, but no single axis is larger than 2 * edgeitems. I doubt that was tested.
|
OK I get it. In both the first and third commit you replace code that worked by recurively indexing the array at each dimension, by code which recursively generates an nd-index and then at the end indexes the array with it. This solves the problem that trying to recursively index a matrix dimension-by-dimension doesn't work since it regenerates new dimensions. |
There was a problem hiding this comment.
Would things break if you called this on data instead of on a? If not, then the changes below to _formatArray are also unnecessary. Though, like for _leading_trailing, the'yre prettier or more performant.
There was a problem hiding this comment.
It depends what you mean by break. Calling this on MaskedArray currently warns and converts masked to nan / errors on int. With your proposed change, it would silently discard the mask.
Ideally, we'd allow the formatters to see the subclasses if they want to, but that's out of scope for 1.14
|
Yep, your summary looks correct.
I'll extract the second commit, since it probably needs a test |
|
Actually this is a pile of tiny and mostly independent things, which I've spun off three new PRs for (#10129, #10130, #10131). I'll revisit the rest of this once those are merged. I think you're right, the changes to |
5283124 to
54dab24
Compare
|
I think we still need to pass a plain ndarray to |
|
You're right though, passing the base class array would work too. I can't immediately think of why that wouldn't be a good idea - and it is currently a little weird that The actual motivation for these PRs was to try and fix the column alignment of |
54dab24 to
109b571
Compare
|
@ahaldane: does this cleanup look like an improvement? Arguments for this approach:
Arguments against:
What I don't care about is whether this is actually the best fix to #8442 - just whether this is a desirable refactor. As you point out above, that issue might be best addressed by just passing in the base class. |
109b571 to
7f6bebe
Compare
There was a problem hiding this comment.
Now only one base case!
|
|
There was a problem hiding this comment.
The rank variable was a workaround for dealing with dtype=object arrays, where arr[i].ndim > arr.ndim is possible, and an external counter is needed. By indexing the array only once, we avoid that confusion.
…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.
7f6bebe to
ed1284e
Compare
|
Closing in favor of a more descriptive PR title with a clean slate of comments, and moving my inline comments into the commit message. Sorry for the noise! |
Use indices not array in the recursion, so that subclasses cannot break it.
Rework of #9816, so fixes gh-8442, gh-5875