From e25f65b406ad6bff39f3a1d1c494a7305acb9c6d Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Thu, 4 May 2023 15:41:19 -0500 Subject: [PATCH 1/2] [TST] Make jpl units instantiated with datetimes consistent with mpl converters --- lib/matplotlib/testing/jpl_units/EpochConverter.py | 4 +--- lib/matplotlib/tests/test_axes.py | 8 ++++---- lib/matplotlib/tests/test_units.py | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/testing/jpl_units/EpochConverter.py b/lib/matplotlib/testing/jpl_units/EpochConverter.py index f42d7b71d041..1edc2acf2b24 100644 --- a/lib/matplotlib/testing/jpl_units/EpochConverter.py +++ b/lib/matplotlib/testing/jpl_units/EpochConverter.py @@ -12,9 +12,7 @@ class EpochConverter(units.ConversionInterface): classes. """ - # julian date reference for "Jan 1, 0001" minus 1 day because - # Matplotlib really wants "Jan 0, 0001" - jdRef = 1721425.5 - 1 + jdRef = 1721425.5 @staticmethod def axisinfo(unit, axis): diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 0d6877f1e364..5743e9ef3964 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -856,8 +856,8 @@ def test_axvspan_epoch(): units.register() # generate some data - t0 = units.Epoch("ET", dt=datetime.datetime(2009, 1, 20)) - tf = units.Epoch("ET", dt=datetime.datetime(2009, 1, 21)) + t0 = units.Epoch("ET", dt=datetime.datetime(2009, 1, 21)) + tf = units.Epoch("ET", dt=datetime.datetime(2009, 1, 22)) dt = units.Duration("ET", units.day.convert("sec")) ax = plt.gca() @@ -871,8 +871,8 @@ def test_axhspan_epoch(): units.register() # generate some data - t0 = units.Epoch("ET", dt=datetime.datetime(2009, 1, 20)) - tf = units.Epoch("ET", dt=datetime.datetime(2009, 1, 21)) + t0 = units.Epoch("ET", dt=datetime.datetime(2009, 1, 21)) + tf = units.Epoch("ET", dt=datetime.datetime(2009, 1, 22)) dt = units.Duration("ET", units.day.convert("sec")) ax = plt.gca() diff --git a/lib/matplotlib/tests/test_units.py b/lib/matplotlib/tests/test_units.py index d3b8c5a71643..c1fad6476648 100644 --- a/lib/matplotlib/tests/test_units.py +++ b/lib/matplotlib/tests/test_units.py @@ -134,7 +134,7 @@ def test_jpl_bar_units(): day = units.Duration("ET", 24.0 * 60.0 * 60.0) x = [0 * units.km, 1 * units.km, 2 * units.km] w = [1 * day, 2 * day, 3 * day] - b = units.Epoch("ET", dt=datetime(2009, 4, 25)) + b = units.Epoch("ET", dt=datetime(2009, 4, 26)) fig, ax = plt.subplots() ax.bar(x, w, bottom=b) ax.set_ylim([b - 1 * day, b + w[-1] + (1.001) * day]) @@ -149,7 +149,7 @@ def test_jpl_barh_units(): day = units.Duration("ET", 24.0 * 60.0 * 60.0) x = [0 * units.km, 1 * units.km, 2 * units.km] w = [1 * day, 2 * day, 3 * day] - b = units.Epoch("ET", dt=datetime(2009, 4, 25)) + b = units.Epoch("ET", dt=datetime(2009, 4, 26)) fig, ax = plt.subplots() ax.barh(x, w, left=b) From 231704fc6d70c8a57d23aa3aadcc1c7bdcf88726 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Thu, 4 May 2023 16:06:45 -0500 Subject: [PATCH 2/2] [TST] Add unit test for consistency of datetime units between mpl.dates and jpl_units --- lib/matplotlib/tests/test_units.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/matplotlib/tests/test_units.py b/lib/matplotlib/tests/test_units.py index c1fad6476648..fa8e5709db64 100644 --- a/lib/matplotlib/tests/test_units.py +++ b/lib/matplotlib/tests/test_units.py @@ -156,6 +156,17 @@ def test_jpl_barh_units(): ax.set_xlim([b - 1 * day, b + w[-1] + (1.001) * day]) +def test_jpl_datetime_units_consistent(): + import matplotlib.testing.jpl_units as units + units.register() + + dt = datetime(2009, 4, 26) + jpl = units.Epoch("ET", dt=dt) + dt_conv = munits.registry.get_converter(dt).convert(dt, None, None) + jpl_conv = munits.registry.get_converter(jpl).convert(jpl, None, None) + assert dt_conv == jpl_conv + + def test_empty_arrays(): # Check that plotting an empty array with a dtype works plt.scatter(np.array([], dtype='datetime64[ns]'), np.array([])) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy