Skip to content

Use warnings.warn, not logging.warning, in microseconds locator warning. #15000

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
Aug 7, 2019
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
7 changes: 4 additions & 3 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,9 +1457,10 @@ def get_locator(self, dmin, dmax):
else:
locator = MicrosecondLocator(interval, tz=self.tz)
if dmin.year > 20 and interval < 1000:
_log.warning('Plotting microsecond time intervals is not well '
'supported. Please see the MicrosecondLocator '
'documentation for details.')
cbook._warn_external(
'Plotting microsecond time intervals is not well '
'supported; please see the MicrosecondLocator '
'documentation for details.')

locator.set_axis(self.axis)

Expand Down
12 changes: 10 additions & 2 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import datetime
try:
from contextlib import nullcontext
except ImportError:
from contextlib import ExitStack as nullcontext # Py 3.6.

import dateutil.tz
import dateutil.rrule
Expand Down Expand Up @@ -369,7 +373,9 @@ def _create_auto_date_locator(date1, date2):
for t_delta, expected in results:
d2 = d1 + t_delta
locator = _create_auto_date_locator(d1, d2)
assert list(map(str, mdates.num2date(locator()))) == expected
with (pytest.warns(UserWarning) if t_delta.microseconds
else nullcontext()):
assert list(map(str, mdates.num2date(locator()))) == expected


def test_auto_date_locator_intmult():
Expand Down Expand Up @@ -444,7 +450,9 @@ def _create_auto_date_locator(date1, date2):
for t_delta, expected in results:
d2 = d1 + t_delta
locator = _create_auto_date_locator(d1, d2)
assert list(map(str, mdates.num2date(locator()))) == expected
with (pytest.warns(UserWarning) if t_delta.microseconds
else nullcontext()):
assert list(map(str, mdates.num2date(locator()))) == expected


def test_concise_formatter():
Expand Down