Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[TST] Make jpl units instantiated with datetimes consistent with mpl converters #25815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/matplotlib/testing/jpl_units/EpochConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
15 changes: 13 additions & 2 deletions lib/matplotlib/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -149,13 +149,24 @@ 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)
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([]))
Expand Down