Skip to content

numpy scalars: should np.set_printoptions(legacy=True) in 0.14.dev reverts to 0.13 printing? #10029

Closed
@lesteve

Description

@lesteve

This is another thing we bumped into our scikit-learn doctests using numpy dev. If this is easy for np.set_printoptions(legacy=True) to use pre-dragon4 printing it would make our life (and the life of other downstream projects bumping into the same problems with doctests) a bit easier when numpy 1.14 is released.

I think the expected behaviour is that np.set_printoptions(legacy=True) does revert to pre-dragon4 format even with all its flaws. If this is not too costly in terms of maintenance, maybe it could be considered? Note we can work-around this issue with doctests ellipsis in scikit-learn.

A snippet to illustrate what I mean in more details:

import numpy as np

try:
    np.set_printoptions(legacy=True)
except TypeError:
    pass

i = 6
numpy_number = np.float64(1.) - i * 1e-17
print('str  : ', numpy_number)
print('repr : ', repr(numpy_number))

Output on numpy master:

str  :  0.9999999999999999
repr :  0.9999999999999999

Output on numpy 1.13:

str  :  1.0
repr :  0.99999999999999989

When using np.set_printoptions(legacy=True) I would expect both output to match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions