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

PR: Use .format() to format floats in array and dataframe editors #20473

Merged
merged 5 commits into from
Feb 4, 2023

Conversation

jitseniesen
Copy link
Member

Description of Changes

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)
  • Included a screenshot or animation (if affecting the UI, see Licecap)

Use format() instead of the % operator to format floating-point numbers in the array and dataframe editors, because this has more functionality and it is modern Python style instead of C-style priintf. For example, with .format() you can specify a thousands separator with , in the format specifier, as shown in the animation below.

A difference with the current version is that there is no initial % character in the format specifier: the user should now give the format as .6g instead of %.6g. However, the config option never had the % character in it, so there is no hange in the configuration.

The second commit contains the actual change from % to .format(), the other commits are preparation and tidying up.

dataframe-format

Issue(s) Resolved

Fixes #14518

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct: Jitse Niesen

This is to prevent shadowing the built-in function format()
This replaces the use of the older and less powerfull % operator
to format floats.
There is no format specification 'r', but complex numbers can
use the same format specifications as real numbers. An empty
format specification just uses the str() representation.
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

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

This is a really nice improvement, thanks @jitseniesen!

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.

How to view numbers in a dataframe with thousands separator in spyder variable explorer?
2 participants