Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Further back-compat fix for subclassed array repr #10674

Conversation

Projects
None yet
2 participants
@ahaldane
Copy link
Member

commented Feb 27, 2018

Fixes #10663

This special-cases 0d arrays so that, only for 0ds, we extract scalars using the ndarray __getitem__ instead of any subclass's __getitem__. In other words it reverts #10544 except for 0d arrays.

This way we avoid the infinite recursion for subclassed-0d arrays that return 0ds instead of scalars when indexed, yet still pass subclassed-0d values on to the formatter functions when printing n-d array elements.

This PR does break two tests involving 0d-subclass-object arrays added in #10544, but those failed anyway in <1.13 and 1.14.0. That is, sub([None, None]) prints as sub([sub(None, dtype=object), sub(None, dtype=object)], dtype=object). I don't see a way of fixing those while not breaking the subclass-nd formatting behavior, which is more important.

@ahaldane ahaldane added this to the 1.14.2 release milestone Feb 27, 2018

@ahaldane ahaldane changed the title BUG: Further back-compat fix for subclassed object arrays BUG: Further back-compat fix for subclassed array repr Feb 27, 2018

@ahaldane ahaldane force-pushed the ahaldane:fix_0d_object_subclass_again_1.14.2 branch from 91c353e to a30eced Feb 27, 2018

@@ -438,14 +438,15 @@ def _array2string(a, options, separator=' ', prefix=""):
# The formatter __init__s in _get_format_function cannot deal with
# subclasses yet, and we also need to avoid recursion issues in
# _formatArray with subclasses which return 0d arrays in place of scalars
a = asarray(a)
data = asarray(a)
if a.shape == ():

This comment has been minimized.

Copy link
@charris

charris Mar 2, 2018

Member

What if a doesn't have shape? Should this be a try?

This comment has been minimized.

Copy link
@charris

charris Mar 2, 2018

Member

I assume this is checked somewhere up above?

This comment has been minimized.

Copy link
@charris

charris Mar 2, 2018

Member

Looks like arraystring requires an ndarray, or subclass thereof, as a, but that is not checked for. The documentation says array_like, which looks incorrect.

@charris charris merged commit c0f864c into numpy:maintenance/1.14.x Mar 2, 2018

4 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
lgtm analysis: Python No alert changes
Details
@charris

This comment has been minimized.

Copy link
Member

commented Mar 2, 2018

Thanks @ahaldane .

@charris

This comment has been minimized.

Copy link
Member

commented Mar 2, 2018

Are you going to make the forward port?

@ahaldane

This comment has been minimized.

Copy link
Member Author

commented Mar 2, 2018

Sure, will do soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.