From 08a800c5b7ee534fe0f53e214763c8c261461218 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 9 Nov 2017 12:53:31 -0800 Subject: [PATCH 1/2] If an axis has a non-None converter, don't allow another non-None --- lib/matplotlib/axis.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 18d54b658ea9..886a544251cc 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1434,6 +1434,13 @@ def update_units(self, data): if converter is None: return False + if (self.converter is not None) and (self.converter != converter): + raise TypeError('Attempting to plot data that is ' + 'registered to be converted with %s but ' + 'is incompatible with existing axis data ' + 'converter %s' % (converter.__class__, + self.converter.__class__)) + neednew = self.converter != converter self.converter = converter default = self.converter.default_units(data, self) From 393a05bb98b1e48add28a14082ea88cdd948f3dd Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 9 Nov 2017 13:01:53 -0800 Subject: [PATCH 2/2] TST: test that two different converters same axis give TypeError --- lib/matplotlib/tests/test_dates.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 437482f5fa2e..e457532fd4aa 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -477,3 +477,14 @@ def test_tz_utc(): def test_num2timedelta(x, tdelta): dt = mdates.num2timedelta(x) assert dt == tdelta + + +def test_one_non_None_converter(): + # test that we only allow one non-None converter at once: + base = datetime.datetime(2017, 1, 1, 0, 10, 0) + time = [base - datetime.timedelta(days=x) for x in range(0, 3)] + data = [0., 2., 4.] + fig, ax = plt.subplots() + ax.plot(time, data) + with pytest.raises(TypeError): + ax.plot(['a', 'b'], [1., 2.])