Skip to content

Commit

Permalink
Merge pull request astropy#15647 from eerovaher/matplotlib-epoch-cert…
Browse files Browse the repository at this point in the history
…ainty

Stop worrying about `matplotlib` default epoch
  • Loading branch information
pllim authored Nov 25, 2023
2 parents 1aa3e6a + 8df34a9 commit 8b9ca69
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
3 changes: 1 addition & 2 deletions astropy/time/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,10 +962,9 @@ class TimePlotDate(TimeFromEpoch):
def epoch(self):
"""Reference epoch time from which the time interval is measured."""
try:
# Matplotlib >= 3.3 has a get_epoch() function
from matplotlib.dates import get_epoch
except ImportError:
# If no get_epoch() then the epoch is '0001-01-01'
# If matplotlib is not installed then the epoch is '0001-01-01'
_epoch = self._epoch
else:
# Get the matplotlib date epoch as an ISOT string in UTC
Expand Down
8 changes: 3 additions & 5 deletions astropy/time/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,11 +1057,9 @@ def test_epoch_times(self):
def test_plot_date(self):
"""Test the plot_date format.
Depending on the situation with matplotlib, this can give different
results because the plot date epoch time changed in matplotlib 3.3. This
test tries to use the matplotlib date2num function to make the test
independent of version, but if matplotlib isn't available then the code
(and test) use the pre-3.3 epoch.
The plot date epoch time changed in matplotlib 3.3. This test
tries to use the matplotlib date2num function, but if matplotlib
isn't available then the code (and test) use the pre-3.3 epoch.
"""
try:
from matplotlib.dates import date2num
Expand Down
15 changes: 1 addition & 14 deletions astropy/visualization/tests/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@

from contextlib import nullcontext

import matplotlib.dates
import matplotlib.pyplot as plt
from erfa import ErfaWarning

from astropy.time import Time
from astropy.visualization.time import time_support

# Matplotlib 3.3 added a settable epoch for plot dates and changed the default
# from 0000-12-31 to 1970-01-01. This can be checked by the existence of
# get_epoch() in matplotlib.dates.
MPL_EPOCH_1970 = hasattr(matplotlib.dates, "get_epoch")

# Since some of the examples below use times/dates in the future, we use the
# TAI time scale to avoid ERFA warnings about dubious years.
DEFAULT_SCALE = "tai"
Expand Down Expand Up @@ -162,14 +156,7 @@ def test_formatter_locator(interval, expected):
("jyear", ["2020", "2040", "2060"]),
("jyear_str", ["J2020.000", "J2040.000", "J2060.000"]),
("mjd", ["60000", "66000", "72000", "78000"]),
(
"plot_date",
(
["18000", "24000", "30000", "36000"]
if MPL_EPOCH_1970
else ["738000", "744000", "750000", "756000"]
),
),
("plot_date", (["18000", "24000", "30000", "36000"])),
("unix", ["1500000000", "2000000000", "2500000000", "3000000000"]),
(
"yday",
Expand Down

0 comments on commit 8b9ca69

Please sign in to comment.