Skip to content

Commit 1095ba5

Browse files
committed
FIX: remove epoch from style and fix tests
1 parent 41f9bf6 commit 1095ba5

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

lib/matplotlib/mpl-data/stylelib/classic.mplstyle

-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ date.autoformatter.hour : %H:%M:%S
229229
date.autoformatter.minute : %H:%M:%S.%f
230230
date.autoformatter.second : %H:%M:%S.%f
231231
date.autoformatter.microsecond : %H:%M:%S.%f
232-
date.epoch : 0000-12-31T00:00:00 # old epoch
233232

234233
### TICKS
235234
# see http://matplotlib.org/api/axis_api.html#matplotlib.axis.Tick

lib/matplotlib/style/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
'webagg.port_retries', 'webagg.open_in_browser', 'backend_fallback',
4040
'toolbar', 'timezone', 'datapath', 'figure.max_open_warning',
4141
'figure.raise_window', 'savefig.directory', 'tk.window_focus',
42-
'docstring.hardcopy'}
42+
'docstring.hardcopy', 'date.epoch'}
4343

4444

4545
def _remove_blacklisted_style_params(d, warn=True):

lib/matplotlib/tests/test_axes.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5415,7 +5415,7 @@ def test_bar_uint8():
54155415
assert patch.xy[0] == x
54165416

54175417

5418-
@image_comparison(['date_timezone_x.png'])
5418+
@image_comparison(['date_timezone_x.png'], tol=1.0)
54195419
def test_date_timezone_x():
54205420
# Tests issue 5575
54215421
time_index = [datetime.datetime(2016, 2, 22, hour=x,
@@ -5450,7 +5450,7 @@ def test_date_timezone_y():
54505450
plt.plot_date([3] * 3, time_index, tz='UTC', xdate=False, ydate=True)
54515451

54525452

5453-
@image_comparison(['date_timezone_x_and_y.png'])
5453+
@image_comparison(['date_timezone_x_and_y.png'], tol=1.0)
54545454
def test_date_timezone_x_and_y():
54555455
# Tests issue 5575
54565456
UTC = datetime.timezone.utc
@@ -6271,7 +6271,8 @@ def test_datetime_masked():
62716271
fig, ax = plt.subplots()
62726272
ax.plot(x, m)
62736273
# these are the default viewlim
6274-
assert ax.get_xlim() == (730120.0, 733773.0)
6274+
dt = mdates.date2num(np.datetime64('0000-12-31'))
6275+
assert ax.get_xlim() == (730120.0 + dt, 733773.0 + dt)
62756276

62766277

62776278
def test_hist_auto_bins():

lib/matplotlib/tests/test_dates.py

+12-23
Original file line numberDiff line numberDiff line change
@@ -300,19 +300,6 @@ def test_drange():
300300
assert mdates.num2date(daterange[-1]) == (end - delta)
301301

302302

303-
def test_empty_date_with_year_formatter():
304-
# exposes sf bug 2861426:
305-
# https://sourceforge.net/tracker/?func=detail&aid=2861426&group_id=80706&atid=560720
306-
307-
# update: I am no longer believe this is a bug, as I commented on
308-
# the tracker. The question is now: what to do with this test
309-
310-
fig, ax = plt.subplots()
311-
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))
312-
with pytest.raises(ValueError):
313-
fig.canvas.draw()
314-
315-
316303
@_new_epoch_decorator
317304
def test_auto_date_locator():
318305
def _create_auto_date_locator(date1, date2):
@@ -759,8 +746,8 @@ def _test_date2num_dst(date_range, tz_convert):
759746

760747
dt_utc = date_range(start=dtstart, freq=interval, periods=N)
761748
dt_bxl = tz_convert(dt_utc, BRUSSELS)
762-
763-
expected_ordinalf = [735322.0 + (i * interval_days) for i in range(N)]
749+
t0 = 735322.0 + mdates.date2num(np.datetime64('0000-12-31'))
750+
expected_ordinalf = [t0 + (i * interval_days) for i in range(N)]
764751
actual_ordinalf = list(mdates.date2num(dt_bxl))
765752

766753
assert actual_ordinalf == expected_ordinalf
@@ -885,10 +872,11 @@ def test_yearlocator_pytz():
885872
locator.create_dummy_axis()
886873
locator.set_view_interval(mdates.date2num(x[0])-1.0,
887874
mdates.date2num(x[-1])+1.0)
888-
889-
np.testing.assert_allclose([733408.208333, 733773.208333, 734138.208333,
890-
734503.208333, 734869.208333,
891-
735234.208333, 735599.208333], locator())
875+
t = np.array([733408.208333, 733773.208333, 734138.208333,
876+
734503.208333, 734869.208333, 735234.208333, 735599.208333])
877+
# convert to new epoch from old...
878+
t = t + mdates.date2num(np.datetime64('0000-12-31'))
879+
np.testing.assert_allclose(t, locator())
892880
expected = ['2009-01-01 00:00:00-05:00',
893881
'2010-01-01 00:00:00-05:00', '2011-01-01 00:00:00-05:00',
894882
'2012-01-01 00:00:00-05:00', '2013-01-01 00:00:00-05:00',
@@ -926,18 +914,19 @@ def test_num2timedelta(x, tdelta):
926914
def test_datetime64_in_list():
927915
dt = [np.datetime64('2000-01-01'), np.datetime64('2001-01-01')]
928916
dn = mdates.date2num(dt)
929-
np.testing.assert_equal(dn, [730120., 730486.])
917+
# convert fixed values from old to new epoch
918+
t = (np.array([730120., 730486.]) +
919+
mdates.date2num(np.datetime64('0000-12-31')))
920+
np.testing.assert_equal(dn, t)
930921

931922

932923
def test_change_epoch():
933924
date = np.datetime64('2000-01-01')
934-
# old epoch (style=Classic)
935-
np.testing.assert_equal(mdates.date2num(date), 730120.0)
936925

937926
with pytest.raises(RuntimeError):
938927
# this should fail here because there is a sentinel on the epoch
939928
# if the epoch has been used then it cannot be set.
940-
mdates.set_epoch('1970-01-01')
929+
mdates.set_epoch('0000-01-01')
941930

942931
# use private method to clear the epoch and allow it to be set...
943932
mdates._reset_epoch_test_example()

0 commit comments

Comments
 (0)