From a9d4f4c692233c4c65e8b86e642ac74053cb16c3 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Thu, 21 Sep 2023 09:41:23 +0200 Subject: [PATCH] Remove Julian date support --- .../next_api_changes/removals/26852-OG.rst | 5 ++ lib/matplotlib/dates.py | 59 ------------------- lib/matplotlib/tests/test_dates.py | 17 ------ 3 files changed, 5 insertions(+), 76 deletions(-) create mode 100644 doc/api/next_api_changes/removals/26852-OG.rst diff --git a/doc/api/next_api_changes/removals/26852-OG.rst b/doc/api/next_api_changes/removals/26852-OG.rst new file mode 100644 index 000000000000..dc7d595f575f --- /dev/null +++ b/doc/api/next_api_changes/removals/26852-OG.rst @@ -0,0 +1,5 @@ +``num2julian``, ``julian2num`` and ``JULIAN_OFFSET`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +... of the `.dates` module are removed without replacements. These were +undocumented and not exported. diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index a11e0d4f1ef6..c12d9f31ba4b 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -205,18 +205,6 @@ UTC = datetime.timezone.utc -@_api.caching_module_getattr -class __getattr__: - JULIAN_OFFSET = _api.deprecated("3.7")(property(lambda self: 1721424.5)) - # Julian date at 0000-12-31 - # note that the Julian day epoch is achievable w/ - # np.datetime64('-4713-11-24T12:00:00'); datetime64 is proleptic - # Gregorian and BC has a one-year offset. So - # np.datetime64('0000-12-31') - np.datetime64('-4713-11-24T12:00') = - # 1721424.5 - # Ref: https://en.wikipedia.org/wiki/Julian_day - - def _get_tzinfo(tz=None): """ Generate `~datetime.tzinfo` from a string or return `~datetime.tzinfo`. @@ -466,53 +454,6 @@ def date2num(d): return d if iterable else d[0] -@_api.deprecated("3.7") -def julian2num(j): - """ - Convert a Julian date (or sequence) to a Matplotlib date (or sequence). - - Parameters - ---------- - j : float or sequence of floats - Julian dates (days relative to 4713 BC Jan 1, 12:00:00 Julian - calendar or 4714 BC Nov 24, 12:00:00, proleptic Gregorian calendar). - - Returns - ------- - float or sequence of floats - Matplotlib dates (days relative to `.get_epoch`). - """ - ep = np.datetime64(get_epoch(), 'h').astype(float) / 24. - ep0 = np.datetime64('0000-12-31T00:00:00', 'h').astype(float) / 24. - # Julian offset defined above is relative to 0000-12-31, but we need - # relative to our current epoch: - dt = __getattr__("JULIAN_OFFSET") - ep0 + ep - return np.subtract(j, dt) # Handles both scalar & nonscalar j. - - -@_api.deprecated("3.7") -def num2julian(n): - """ - Convert a Matplotlib date (or sequence) to a Julian date (or sequence). - - Parameters - ---------- - n : float or sequence of floats - Matplotlib dates (days relative to `.get_epoch`). - - Returns - ------- - float or sequence of floats - Julian dates (days relative to 4713 BC Jan 1, 12:00:00). - """ - ep = np.datetime64(get_epoch(), 'h').astype(float) / 24. - ep0 = np.datetime64('0000-12-31T00:00:00', 'h').astype(float) / 24. - # Julian offset defined above is relative to 0000-12-31, but we need - # relative to our current epoch: - dt = __getattr__("JULIAN_OFFSET") - ep0 + ep - return np.add(n, dt) # Handles both scalar & nonscalar j. - - def num2date(x, tz=None): """ Convert Matplotlib dates to `~datetime.datetime` objects. diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 8995b9b35f09..4133524e0e1a 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -6,7 +6,6 @@ import numpy as np import pytest -import matplotlib as mpl from matplotlib import rc_context, style import matplotlib.dates as mdates import matplotlib.pyplot as plt @@ -1282,22 +1281,6 @@ def test_change_interval_multiples(): assert ax.get_xticklabels()[1].get_text() == 'Feb 01 2020' -def test_julian2num(): - mdates._reset_epoch_test_example() - mdates.set_epoch('0000-12-31') - with pytest.warns(mpl.MatplotlibDeprecationWarning): - # 2440587.5 is julian date for 1970-01-01T00:00:00 - # https://en.wikipedia.org/wiki/Julian_day - assert mdates.julian2num(2440588.5) == 719164.0 - assert mdates.num2julian(719165.0) == 2440589.5 - # set back to the default - mdates._reset_epoch_test_example() - mdates.set_epoch('1970-01-01T00:00:00') - with pytest.warns(mpl.MatplotlibDeprecationWarning): - assert mdates.julian2num(2440588.5) == 1.0 - assert mdates.num2julian(2.0) == 2440589.5 - - def test_DateLocator(): locator = mdates.DateLocator() # Test nonsingular