Skip to content

Commit c2aa4ee

Browse files
authored
Merge pull request #25815 from ksunden/jpl_unit_date_ob1
[TST] Make jpl units instantiated with datetimes consistent with mpl converters
2 parents 85213e2 + 231704f commit c2aa4ee

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

lib/matplotlib/testing/jpl_units/EpochConverter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class EpochConverter(units.ConversionInterface):
1212
classes.
1313
"""
1414

15-
# julian date reference for "Jan 1, 0001" minus 1 day because
16-
# Matplotlib really wants "Jan 0, 0001"
17-
jdRef = 1721425.5 - 1
15+
jdRef = 1721425.5
1816

1917
@staticmethod
2018
def axisinfo(unit, axis):

lib/matplotlib/tests/test_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,8 @@ def test_axvspan_epoch():
922922
units.register()
923923

924924
# generate some data
925-
t0 = units.Epoch("ET", dt=datetime.datetime(2009, 1, 20))
926-
tf = units.Epoch("ET", dt=datetime.datetime(2009, 1, 21))
925+
t0 = units.Epoch("ET", dt=datetime.datetime(2009, 1, 21))
926+
tf = units.Epoch("ET", dt=datetime.datetime(2009, 1, 22))
927927
dt = units.Duration("ET", units.day.convert("sec"))
928928

929929
ax = plt.gca()
@@ -937,8 +937,8 @@ def test_axhspan_epoch():
937937
units.register()
938938

939939
# generate some data
940-
t0 = units.Epoch("ET", dt=datetime.datetime(2009, 1, 20))
941-
tf = units.Epoch("ET", dt=datetime.datetime(2009, 1, 21))
940+
t0 = units.Epoch("ET", dt=datetime.datetime(2009, 1, 21))
941+
tf = units.Epoch("ET", dt=datetime.datetime(2009, 1, 22))
942942
dt = units.Duration("ET", units.day.convert("sec"))
943943

944944
ax = plt.gca()

lib/matplotlib/tests/test_units.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_jpl_bar_units():
134134
day = units.Duration("ET", 24.0 * 60.0 * 60.0)
135135
x = [0 * units.km, 1 * units.km, 2 * units.km]
136136
w = [1 * day, 2 * day, 3 * day]
137-
b = units.Epoch("ET", dt=datetime(2009, 4, 25))
137+
b = units.Epoch("ET", dt=datetime(2009, 4, 26))
138138
fig, ax = plt.subplots()
139139
ax.bar(x, w, bottom=b)
140140
ax.set_ylim([b - 1 * day, b + w[-1] + (1.001) * day])
@@ -149,13 +149,24 @@ def test_jpl_barh_units():
149149
day = units.Duration("ET", 24.0 * 60.0 * 60.0)
150150
x = [0 * units.km, 1 * units.km, 2 * units.km]
151151
w = [1 * day, 2 * day, 3 * day]
152-
b = units.Epoch("ET", dt=datetime(2009, 4, 25))
152+
b = units.Epoch("ET", dt=datetime(2009, 4, 26))
153153

154154
fig, ax = plt.subplots()
155155
ax.barh(x, w, left=b)
156156
ax.set_xlim([b - 1 * day, b + w[-1] + (1.001) * day])
157157

158158

159+
def test_jpl_datetime_units_consistent():
160+
import matplotlib.testing.jpl_units as units
161+
units.register()
162+
163+
dt = datetime(2009, 4, 26)
164+
jpl = units.Epoch("ET", dt=dt)
165+
dt_conv = munits.registry.get_converter(dt).convert(dt, None, None)
166+
jpl_conv = munits.registry.get_converter(jpl).convert(jpl, None, None)
167+
assert dt_conv == jpl_conv
168+
169+
159170
def test_empty_arrays():
160171
# Check that plotting an empty array with a dtype works
161172
plt.scatter(np.array([], dtype='datetime64[ns]'), np.array([]))

0 commit comments

Comments
 (0)
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