Skip to content

Inline or simplify FooFormatter.pprint_val. #12950

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

Merged
merged 1 commit into from
Feb 27, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Dec 8, 2018

This avoids confusion between the three implementations
(OldScalarFormatter, ScalarFormatter, and LogFormatter).

OldScalarFormatter._pprint_val and ScalarFormatter._pprint_val are not
used elsewhere and can be inlined.
LogFormatter._pprint_val is also used by LogFormatterExponent and must
be kept (even though it looks likely that LogFormatterExponent can also
be simplified , e.g. the test
abs(math.log(x) / math.log(self._base)) > 10000
is basically never True for any realistic case -- but that'll be for
another time).

Followup to #12924.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

This avoids confusion between the three implementations
(OldScalarFormatter, ScalarFormatter, and LogFormatter).

OldScalarFormatter._pprint_val and ScalarFormatter._pprint_val are not
used elsewhere and can be inlined.
LogFormatter._pprint_val is also used by LogFormatterExponent and must
be kept (even though it looks likely that LogFormatterExponent can also
be simplified , e.g. the test
`abs(math.log(x) / math.log(self._base)) > 10000`
is basically never True for any realistic case -- but that'll be for
another time).
@anntzer anntzer added this to the v3.1 milestone Dec 8, 2018
@timhoffm
Copy link
Member

timhoffm commented Dec 9, 2018

-0.5 on inlineing. Pretty-printing takes a number of lines of code and is a semantic operation of it's own. Therefore it deserves its own function, even if it's just used once.

I would be positive on unifying the API, or maybe moving it to a cbook function.

@anntzer
Copy link
Contributor Author

anntzer commented Dec 9, 2018

The problem is that different formatters can't even agree on what pretty-printing means, even though it's pretty much orthogonal to their functionality: Why does ScalarFormatter.pprint_val obey useLocale but not OldScalarFormatter.pprint_val or LogFormatter.pprint_val? Why does OldScalarFormatter.pprint_val strip the + sign from the exponent but not LogFormatter?
Separating this step from __call__ happens at a pretty arbitrary place anyway (OldScalarFormatter and LogFormatter compute the format string in pprint_val, but ScalarFormatter does so in __call__ so I dispute the assertion that it is (as implemented right now) a semantic operation at all.

@timhoffm
Copy link
Member

timhoffm commented Dec 9, 2018

I agree with your assessment of the current state. However, my recommendation to changing a bad code structure is to make a better structure, not to throw away all structure.

@anntzer
Copy link
Contributor Author

anntzer commented Dec 9, 2018

Well, the good thing is that at least now the structure is private, so we can play with it in whatever way we want...

@jklymak
Copy link
Member

jklymak commented Feb 27, 2019

Lets merge and if we want to re-factor privately we can...

@jklymak jklymak merged commit 9aea67e into matplotlib:master Feb 27, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 27, 2019
@anntzer anntzer deleted the pprint_val branch February 28, 2019 01:02
jklymak added a commit that referenced this pull request Feb 28, 2019
…950-on-v3.1.x

Backport PR #12950 on branch v3.1.x (Inline or simplify FooFormatter.pprint_val.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants