From 5dcab5e32c5b1143f574c48a9ccce7475f8b2860 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 9 Jan 2018 20:22:40 +0000 Subject: [PATCH 1/3] If a value to convert doesn't have units, just return --- lib/matplotlib/axis.py | 4 ++++ lib/matplotlib/dates.py | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index ac6bf3425c41..fd92bb5c5214 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1498,6 +1498,10 @@ def have_units(self): return self.converter is not None or self.units is not None def convert_units(self, x): + # If x is already a number, doesn't need converting + if munits.ConversionInterface.is_numlike(x): + return x + if self.converter is None: self.converter = munits.registry.get_converter(x) diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index f71f12eea32e..702959e2feab 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -1738,8 +1738,6 @@ def convert(value, unit, axis): The *unit* and *axis* arguments are not used. """ - if units.ConversionInterface.is_numlike(value): - return value return date2num(value) @staticmethod From ca00ccaf196c963c5c67af29680da879f9ac4e2b Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 9 Jan 2018 20:57:13 +0000 Subject: [PATCH 2/3] Allow custom unit class to not be iterable --- lib/matplotlib/tests/test_units.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_units.py b/lib/matplotlib/tests/test_units.py index f72ac2c60476..aea1df21fa00 100644 --- a/lib/matplotlib/tests/test_units.py +++ b/lib/matplotlib/tests/test_units.py @@ -31,7 +31,10 @@ def __getattr__(self, attr): return getattr(self.magnitude, attr) def __getitem__(self, item): - return Quantity(self.magnitude[item], self.units) + if iterable(self.magnitude): + return Quantity(self.magnitude[item], self.units) + else: + return Quantity(self.magnitude[item], self.units) def __array__(self): return np.asarray(self.magnitude) From 4f25759748da507842c2c232dcf01394f3a595c0 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 9 Jan 2018 21:09:14 +0000 Subject: [PATCH 3/3] Actually make units possibly not iterable --- lib/matplotlib/tests/test_units.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_units.py b/lib/matplotlib/tests/test_units.py index aea1df21fa00..14e8341e4b5d 100644 --- a/lib/matplotlib/tests/test_units.py +++ b/lib/matplotlib/tests/test_units.py @@ -34,7 +34,7 @@ def __getitem__(self, item): if iterable(self.magnitude): return Quantity(self.magnitude[item], self.units) else: - return Quantity(self.magnitude[item], self.units) + return Quantity(self.magnitude, self.units) def __array__(self): return np.asarray(self.magnitude)