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

Skip to content

Commit a8d2738

Browse files
authored
Merge pull request #15000 from anntzer/microwarn
Use warnings.warn, not logging.warning, in microseconds locator warning.
2 parents d95e3f8 + bed898d commit a8d2738

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/matplotlib/dates.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,9 +1457,10 @@ def get_locator(self, dmin, dmax):
14571457
else:
14581458
locator = MicrosecondLocator(interval, tz=self.tz)
14591459
if dmin.year > 20 and interval < 1000:
1460-
_log.warning('Plotting microsecond time intervals is not well '
1461-
'supported. Please see the MicrosecondLocator '
1462-
'documentation for details.')
1460+
cbook._warn_external(
1461+
'Plotting microsecond time intervals is not well '
1462+
'supported; please see the MicrosecondLocator '
1463+
'documentation for details.')
14631464

14641465
locator.set_axis(self.axis)
14651466

lib/matplotlib/tests/test_dates.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import datetime
2+
try:
3+
from contextlib import nullcontext
4+
except ImportError:
5+
from contextlib import ExitStack as nullcontext # Py 3.6.
26

37
import dateutil.tz
48
import dateutil.rrule
@@ -369,7 +373,9 @@ def _create_auto_date_locator(date1, date2):
369373
for t_delta, expected in results:
370374
d2 = d1 + t_delta
371375
locator = _create_auto_date_locator(d1, d2)
372-
assert list(map(str, mdates.num2date(locator()))) == expected
376+
with (pytest.warns(UserWarning) if t_delta.microseconds
377+
else nullcontext()):
378+
assert list(map(str, mdates.num2date(locator()))) == expected
373379

374380

375381
def test_auto_date_locator_intmult():
@@ -444,7 +450,9 @@ def _create_auto_date_locator(date1, date2):
444450
for t_delta, expected in results:
445451
d2 = d1 + t_delta
446452
locator = _create_auto_date_locator(d1, d2)
447-
assert list(map(str, mdates.num2date(locator()))) == expected
453+
with (pytest.warns(UserWarning) if t_delta.microseconds
454+
else nullcontext()):
455+
assert list(map(str, mdates.num2date(locator()))) == expected
448456

449457

450458
def test_concise_formatter():

0 commit comments

Comments
 (0)