Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Add digits parameter to EngFormatter for significant figures #30827

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

Open
giparraguirre wants to merge 4 commits into matplotlib:main
base: main
Choose a base branch
Loading
from giparraguirre:enh-engformatter-digits

Conversation

@giparraguirre
Copy link

@giparraguirre giparraguirre commented Dec 8, 2025

...ed digits parameter for significant figure formatting, trim_zeros parameter to control trailing zeros, ensured mutual exclusion with places parameter, implemented boundary rollover (e.g., 999.95 → 1.000 k), added comprehensive tests for new functionality, and maintained backward compatibility. Should address #30727

PR summary

PR checklist

Closes #30727

...ed digits parameter for significant figure formatting, trim_zeros parameter to control trailing zeros, ensured mutual exclusion with places parameter, implemented boundary rollover (e.g., 999.95 → 1.000 k), added comprehensive tests for new functionality, and maintained backward compatibility. Should address matplotlib#30727 
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Please add a What's new entry

"Cannot specify 'places' and 'digits'"
)

if trim_zeros not in ("keep", "trim"):
Copy link
Member

@timhoffm timhoffm Dec 9, 2025

Choose a reason for hiding this comment

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

Is there a reason to not make trim_zeros a bool?

Copy link
Author

@giparraguirre giparraguirre Dec 9, 2025

Choose a reason for hiding this comment

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

I initially chose string values to make the intent more explicit in code (e.g., trim_zeros="trim" reads clearly), but a bool would be simpler. I'm happy to change it to 'trim_zeros=False' to keep trailing zeros (i.e., default) and 'trim_zeros=True' to trim trailing zeros. Would you prefer this bool approach?

"""
sign = 1
fmt = "g" if self.places is None elsef".{self.places:d}f"
fmt = "g" if self.places is None andself.digitsisNoneelseNone
Copy link
Member

@timhoffm timhoffm Dec 9, 2025
edited
Loading

Choose a reason for hiding this comment

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

Move to the block "# Determine format string based on digits or places" so that all the logic is in one place.

Copy link
Author

@giparraguirre giparraguirre Dec 9, 2025

Choose a reason for hiding this comment

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

Sure thing!

Copy link
Member

Please fix the issues marked by ruff and mypy-stubtest.

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

Reviewers

@timhoffm timhoffm timhoffm left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[ENH]: EngFormatter to print as significant figures

AltStyle によって変換されたページ (->オリジナル) /