Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unit handling improvements #18531

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
Sep 22, 2020
Merged

Unit handling improvements #18531

merged 1 commit into from
Sep 22, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 20, 2020

PR Summary

1st commit: Change the signature of _process_unit_info to make it work both for the 2D and the 3D cases (instead of passing xdata, ydata as separate named parameters, pass a single axis-to-dataset mapping). This avoids having to redefine it for the 3D case.

2nd commit: Make _process_unit_info directly perform unit conversion as well (nearly all calls to _process_unit_info are followed by a call to convert_x/yunits, and it semantically makes sense to have both of them together, too).

3rd commit: Fix incorrect unit application for horizontal histograms (which should use the y units, not the x units).

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/next_api_changes/* if API changed in a backward-incompatible way

@anntzer anntzer added this to the v3.4.0 milestone Sep 20, 2020
@anntzer anntzer force-pushed the units branch 2 times, most recently from db696a4 to 98ebd9d Compare September 20, 2020 15:44
datasets : dict
Mapping of axis names (per `._get_axis_map`) to datasets.
kwargs : dict
Other parameters from which unit info may be popped. Note that
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit vague. Can we be more explicit? Which entries will be popped under which conditions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@tacaswell
Copy link
Member

I am a bit concerned about the dict order -> list return mapping, but am not going to block over it.

@anntzer
Copy link
Contributor Author

anntzer commented Sep 20, 2020

Actually I realized passing a list of pairs is nicer for another reason: sometimes you need to convert multiple datasets on a single axis, and convert_units does not necessarily support converting a ragged array of them, so we need to instead pass them one at a time.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

(modulo sorting out why this broke the docs)

@anntzer
Copy link
Contributor Author

anntzer commented Sep 22, 2020

it was too hard to maintain a sensible commit log so I just squashed everything.


Parameters
----------
datasets : list
Copy link
Member

Choose a reason for hiding this comment

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

You might consider accepting a single tuple as well. This seems to be a common use case and results in a little less cluttered code. But no strong opinion, it's interal anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it really gains us much, and would make the implementation (and documentation) more complex. Let's say I wouldn't block a PR implementing that, but won't do it here.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. Even though the added implementation complexity is just

if isinstance(datasets, tuple):
    datasets = [datasets]

... and fix incorrect converter used for horizontal histograms.
@timhoffm timhoffm merged commit ba43765 into matplotlib:master Sep 22, 2020
@anntzer anntzer deleted the units branch September 22, 2020 15:26
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.

4 participants