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

Make %precision work for numpy.float64 type #12902

Merged
merged 3 commits into from Apr 17, 2021
Merged

Conversation

petercorke
Copy link
Contributor

Many NumPy functions return a float64 type whose display does not obey %precision, for example:

In [4]: precision 2
Out[4]: '%.2f'

In [5]: np.linalg.norm([1,2])
Out[5]: 2.23606797749979

IPython already sets precision for NumPy arrays using set_printoptions() but this does not affect the format for scalars.

This simple change sets the formatter for float64 to be the same as for float so that any changes to precision will take effect for float64.

Copy link
Member

@MrMino MrMino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't investigated all of the implications of this approach yet, but this could use a test & appropriate mention in the %precision docs.

Also, merging this will require adding a "What's new" fragment to the pr directory.

See CONTRIBUTING.md#Pull Requests and docs/source/whatsnew/pr/README.md

@petercorke
Copy link
Contributor Author

Just this section?
Testing should be with formatters or with magics?

@MrMino
Copy link
Member

MrMino commented Apr 11, 2021

Just this section?

Yes, here to be precise (the highlight in your link didn't work for me).

Testing should be with formatters or with magics?

I would do both, but at least having a doctest-style test that checks whether the precision has actually changed after using %precision should be sufficient.

Thanks!

@Carreau Carreau added this to the 8.0 milestone Apr 17, 2021
@Carreau
Copy link
Member

Carreau commented Apr 17, 2021

Let's get that in and I'll open an issue about the test and what's new.
Especially doctest might be tricky as we are trying to drop support for nose (incompatible 3.10) and pytest does not currently run doctests.

@Carreau Carreau merged commit 67d4444 into ipython:master Apr 17, 2021
@petercorke
Copy link
Contributor Author

Thanks, I was going to do this tomorrow... Do you still want me to do the docktest things? I know what it is but have never used it before.

@MrMino
Copy link
Member

MrMino commented Apr 17, 2021

@petercorke It's always appreciated if you try. If you run into issues you can always communicate them through #12917 and that way we'll at least know where the problems are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants