Skip to content

Conversation

@giparraguirre
Copy link

…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

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

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 else f".{self.places:d}f"
fmt = "g" if self.places is None and self.digits is None else None
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.

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

Copy link
Author

Choose a reason for hiding this comment

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

Sure thing!

@timhoffm
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: EngFormatter to print as significant figures

2 participants