Skip to content

Commit a9d4f4c

Browse files
committed
Remove Julian date support
1 parent 2cbdff8 commit a9d4f4c

File tree

3 files changed

+5
-76
lines changed

3 files changed

+5
-76
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``num2julian``, ``julian2num`` and ``JULIAN_OFFSET``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... of the `.dates` module are removed without replacements. These were
5+
undocumented and not exported.

lib/matplotlib/dates.py

-59
Original file line numberDiff line numberDiff line change
@@ -205,18 +205,6 @@
205205
UTC = datetime.timezone.utc
206206

207207

208-
@_api.caching_module_getattr
209-
class __getattr__:
210-
JULIAN_OFFSET = _api.deprecated("3.7")(property(lambda self: 1721424.5))
211-
# Julian date at 0000-12-31
212-
# note that the Julian day epoch is achievable w/
213-
# np.datetime64('-4713-11-24T12:00:00'); datetime64 is proleptic
214-
# Gregorian and BC has a one-year offset. So
215-
# np.datetime64('0000-12-31') - np.datetime64('-4713-11-24T12:00') =
216-
# 1721424.5
217-
# Ref: https://en.wikipedia.org/wiki/Julian_day
218-
219-
220208
def _get_tzinfo(tz=None):
221209
"""
222210
Generate `~datetime.tzinfo` from a string or return `~datetime.tzinfo`.
@@ -466,53 +454,6 @@ def date2num(d):
466454
return d if iterable else d[0]
467455

468456

469-
@_api.deprecated("3.7")
470-
def julian2num(j):
471-
"""
472-
Convert a Julian date (or sequence) to a Matplotlib date (or sequence).
473-
474-
Parameters
475-
----------
476-
j : float or sequence of floats
477-
Julian dates (days relative to 4713 BC Jan 1, 12:00:00 Julian
478-
calendar or 4714 BC Nov 24, 12:00:00, proleptic Gregorian calendar).
479-
480-
Returns
481-
-------
482-
float or sequence of floats
483-
Matplotlib dates (days relative to `.get_epoch`).
484-
"""
485-
ep = np.datetime64(get_epoch(), 'h').astype(float) / 24.
486-
ep0 = np.datetime64('0000-12-31T00:00:00', 'h').astype(float) / 24.
487-
# Julian offset defined above is relative to 0000-12-31, but we need
488-
# relative to our current epoch:
489-
dt = __getattr__("JULIAN_OFFSET") - ep0 + ep
490-
return np.subtract(j, dt) # Handles both scalar & nonscalar j.
491-
492-
493-
@_api.deprecated("3.7")
494-
def num2julian(n):
495-
"""
496-
Convert a Matplotlib date (or sequence) to a Julian date (or sequence).
497-
498-
Parameters
499-
----------
500-
n : float or sequence of floats
501-
Matplotlib dates (days relative to `.get_epoch`).
502-
503-
Returns
504-
-------
505-
float or sequence of floats
506-
Julian dates (days relative to 4713 BC Jan 1, 12:00:00).
507-
"""
508-
ep = np.datetime64(get_epoch(), 'h').astype(float) / 24.
509-
ep0 = np.datetime64('0000-12-31T00:00:00', 'h').astype(float) / 24.
510-
# Julian offset defined above is relative to 0000-12-31, but we need
511-
# relative to our current epoch:
512-
dt = __getattr__("JULIAN_OFFSET") - ep0 + ep
513-
return np.add(n, dt) # Handles both scalar & nonscalar j.
514-
515-
516457
def num2date(x, tz=None):
517458
"""
518459
Convert Matplotlib dates to `~datetime.datetime` objects.

lib/matplotlib/tests/test_dates.py

-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
import pytest
88

9-
import matplotlib as mpl
109
from matplotlib import rc_context, style
1110
import matplotlib.dates as mdates
1211
import matplotlib.pyplot as plt
@@ -1282,22 +1281,6 @@ def test_change_interval_multiples():
12821281
assert ax.get_xticklabels()[1].get_text() == 'Feb 01 2020'
12831282

12841283

1285-
def test_julian2num():
1286-
mdates._reset_epoch_test_example()
1287-
mdates.set_epoch('0000-12-31')
1288-
with pytest.warns(mpl.MatplotlibDeprecationWarning):
1289-
# 2440587.5 is julian date for 1970-01-01T00:00:00
1290-
# https://en.wikipedia.org/wiki/Julian_day
1291-
assert mdates.julian2num(2440588.5) == 719164.0
1292-
assert mdates.num2julian(719165.0) == 2440589.5
1293-
# set back to the default
1294-
mdates._reset_epoch_test_example()
1295-
mdates.set_epoch('1970-01-01T00:00:00')
1296-
with pytest.warns(mpl.MatplotlibDeprecationWarning):
1297-
assert mdates.julian2num(2440588.5) == 1.0
1298-
assert mdates.num2julian(2.0) == 2440589.5
1299-
1300-
13011284
def test_DateLocator():
13021285
locator = mdates.DateLocator()
13031286
# Test nonsingular

0 commit comments

Comments
 (0)