Skip to content

API: treat xunits=None and yunits=None as "default" - #17828

Merged
efiring merged 1 commit into
matplotlib:masterfrom
tacaswell:fix_none_units
Jul 5, 2020
Merged

efiring merged 1 commit into
matplotlib:masterfrom
tacaswell:fix_none_units

Conversation

@tacaswell

Copy link
Copy Markdown
Member

PR Summary

If the user passes None, treat as if they had passed nothing and do
not try to change the units on the respective axis.

closes #11095

I still need to write an API changes note (even though this is fixing a regression, it is a very old regression).

I don't think this conflicts with #17824 as the improved error message is a good idea independent of if this goes in.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • Documented in doc/api/next_api_changes/* if API changed in a backward-incompatible way

@tacaswell tacaswell added this to the v3.4.0 milestone Jul 3, 2020
Comment thread lib/matplotlib/tests/test_category.py Outdated

@pytest.mark.style('default')
@check_figures_equal(extensions=["png"])
def test_overliding_units(fig_test, fig_ref):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"overliding"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

l and r are next to each other on my keyboard. I wish I could blame all of my miss-spellings on poor typing as easily as this one...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah, dvorak? :)

Comment on lines +278 to +284
from datetime import datetime

t0 = datetime(2018, 3, 1)
t1 = datetime(2018, 3, 2)
t2 = datetime(2018, 3, 3)
t3 = datetime(2018, 3, 4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what's the point of adding in the datetime here if that's not what's being tested?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is a converter class that does not care about the value of Axis.units, but I think it is worth putting units on both Axis.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be better to test using some data that does care about/use units? I'm wondering if datetime always has the units set to None all the time anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The string catarogicals do use Axis.units to store critical state (which is what broke in #11095).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh woops, I missed that categoricals were being plotted too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tacaswell so that's what concerns me, that you're putting two potential points of failure in this test - when it fails will it be easy to see that it was the categoricals that broke this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

All of our tests as pretty much closer to integration tests than unit tests. I am optimistic that if (when) this break who ever is debugging it will be able to sort out the root cause with out too much trouble.

@tacaswell
tacaswell force-pushed the fix_none_units branch 2 times, most recently from 8649ad9 to f0851fc Compare July 3, 2020 16:56
@tacaswell
tacaswell marked this pull request as ready for review July 3, 2020 16:56
Comment on lines +278 to +284
from datetime import datetime

t0 = datetime(2018, 3, 1)
t1 = datetime(2018, 3, 2)
t2 = datetime(2018, 3, 3)
t3 = datetime(2018, 3, 4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be better to test using some data that does care about/use units? I'm wondering if datetime always has the units set to None all the time anyway.

@tacaswell tacaswell added API: changes Changes to the public API, typically requiring deprecation. API: consistency Consistency of the matplotlib API, including naming, behavior, defaults, … labels Jul 3, 2020

@efiring efiring left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just typos; otherwise looks fine.

Comment thread lib/matplotlib/axes/_base.py Outdated
.. warning ::

This method may mutate the dictionary passed in an kwargs and
the Axes instances attached to this Axes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"passed in an kwargs" -> "passed in as kwargs"
"the Axes instances" -> "the Axis instances"

If the user passes None, treat as if they had passed nothing and do
not try to change the units on the respective axis.

closes matplotlib#11095

Co-authored-by: David Stansby <dstansby@gmail.com>
@efiring
efiring merged commit d266e71 into matplotlib:master Jul 5, 2020
@tacaswell
tacaswell deleted the fix_none_units branch July 5, 2020 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API: changes Changes to the public API, typically requiring deprecation. API: consistency Consistency of the matplotlib API, including naming, behavior, defaults, … topic: units and array ducktypes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repeated plot calls with xunits=None throws exception

5 participants