Skip to content

Remove Julian date support #26852

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 1 commit into from
Sep 21, 2023
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/removals/26852-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``num2julian``, ``julian2num`` and ``JULIAN_OFFSET``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

... of the `.dates` module are removed without replacements. These were
undocumented and not exported.
59 changes: 0 additions & 59 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 0 additions & 17 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down