MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_yearlocator_pytz

Function test_yearlocator_pytz

lib/matplotlib/tests/test_dates.py:1114–1143  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1112
1113@pytest.mark.pytz
1114def test_yearlocator_pytz():
1115 pytz = pytest.importorskip("pytz")
1116
1117 tz = pytz.timezone('America/New_York')
1118 x = [tz.localize(datetime.datetime(2010, 1, 1))
1119 + datetime.timedelta(i) for i in range(2000)]
1120 locator = mdates.AutoDateLocator(interval_multiples=True, tz=tz)
1121 locator.create_dummy_axis()
1122 locator.axis.set_view_interval(mdates.date2num(x[0])-1.0,
1123 mdates.date2num(x[-1])+1.0)
1124 t = np.array([733408.208333, 733773.208333, 734138.208333,
1125 734503.208333, 734869.208333, 735234.208333, 735599.208333])
1126 # convert to new epoch from old...
1127 t = t + mdates.date2num(np.datetime64('0000-12-31'))
1128 np.testing.assert_allclose(t, locator())
1129 expected = ['2009-01-01 00:00:00-05:00',
1130 '2010-01-01 00:00:00-05:00', '2011-01-01 00:00:00-05:00',
1131 '2012-01-01 00:00:00-05:00', '2013-01-01 00:00:00-05:00',
1132 '2014-01-01 00:00:00-05:00', '2015-01-01 00:00:00-05:00']
1133 st = list(map(str, mdates.num2date(locator(), tz=tz)))
1134 assert st == expected
1135 assert np.allclose(locator.tick_values(x[0], x[1]), np.array(
1136 [14610.20833333, 14610.33333333, 14610.45833333, 14610.58333333,
1137 14610.70833333, 14610.83333333, 14610.95833333, 14611.08333333,
1138 14611.20833333]))
1139 assert np.allclose(locator.get_locator(x[1], x[0]).tick_values(x[0], x[1]),
1140 np.array(
1141 [14610.20833333, 14610.33333333, 14610.45833333, 14610.58333333,
1142 14610.70833333, 14610.83333333, 14610.95833333, 14611.08333333,
1143 14611.20833333]))
1144
1145
1146def test_YearLocator():

Callers

nothing calls this directly

Calls 6

tick_valuesMethod · 0.95
get_locatorMethod · 0.95
create_dummy_axisMethod · 0.80
allcloseMethod · 0.80
set_view_intervalMethod · 0.45
tick_valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…