Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ae42f5

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

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,11 @@ def test_single_date():
652652
plt.rcParams['axes.formatter.limits'] = -7, 7
653653

654654
time1 = [721964.0]
655+
dt = mdates.date2num(np.datetime64('0000-12-31'))
655656
data1 = [-65.54]
656657

657658
fig, ax = plt.subplots(2, 1)
658-
ax[0].plot_date(time1, data1, 'o', color='r')
659+
ax[0].plot_date(time1 + dt, data1, 'o', color='r')
659660
ax[1].plot(time1, data1, 'o', color='r')
660661

661662

@@ -899,7 +900,7 @@ def test_axvspan_epoch():
899900
ax.set_xlim(t0 - 5.0*dt, tf + 5.0*dt)
900901

901902

902-
@image_comparison(['axhspan_epoch'])
903+
@image_comparison(['axhspan_epoch'], tol=0.02)
903904
def test_axhspan_epoch():
904905
import matplotlib.testing.jpl_units as units
905906
units.register()
@@ -5415,7 +5416,7 @@ def test_bar_uint8():
54155416
assert patch.xy[0] == x
54165417

54175418

5418-
@image_comparison(['date_timezone_x.png'])
5419+
@image_comparison(['date_timezone_x.png'], tol=1.0)
54195420
def test_date_timezone_x():
54205421
# Tests issue 5575
54215422
time_index = [datetime.datetime(2016, 2, 22, hour=x,
@@ -5450,7 +5451,7 @@ def test_date_timezone_y():
54505451
plt.plot_date([3] * 3, time_index, tz='UTC', xdate=False, ydate=True)
54515452

54525453

5453-
@image_comparison(['date_timezone_x_and_y.png'])
5454+
@image_comparison(['date_timezone_x_and_y.png'], tol=1.0)
54545455
def test_date_timezone_x_and_y():
54555456
# Tests issue 5575
54565457
UTC = datetime.timezone.utc
@@ -6271,7 +6272,8 @@ def test_datetime_masked():
62716272
fig, ax = plt.subplots()
62726273
ax.plot(x, m)
62736274
# these are the default viewlim
6274-
assert ax.get_xlim() == (730120.0, 733773.0)
6275+
dt = mdates.date2num(np.datetime64('0000-12-31'))
6276+
assert ax.get_xlim() == (730120.0 + dt, 733773.0 + dt)
62756277

62766278

62776279
def test_hist_auto_bins():

lib/matplotlib/tests/test_dates.py

Lines changed: 12 additions & 23 deletions
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)