8000 FIX: properly handle dates when intmult is true · matplotlib/matplotlib@8e51231 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e51231

Browse files
committed
FIX: properly handle dates when intmult is true
1 parent 09d8da2 commit 8e51231

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

lib/matplotlib/dates.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ def __init__(self, tz=None, minticks=5, maxticks=None,
13041304
# Swap "3" for "4" in the DAILY list; If we use 3 we get bad
13051305
# tick loc for months w/ 31 days: 1, 4, ..., 28, 31, 1
13061306
# If we use 4 then we get: 1, 5, ... 25, 29, 1
1307-
self.intervald[DAILY] = [1, 2, 4, 7, 14, 21]
1307+
self.intervald[DAILY] = [1, 2, 4, 7, 14]
13081308

13091309
self._byranges = [None, range(1, 13), range(1, 32),
13101310
range(0, 24), range(0, 60), range(0, 60), None]
@@ -1353,7 +1353,6 @@ def get_locator(self, dmin, dmax):
13531353
if dmin > dmax:
13541354
delta = -delta
13551355
tdelta = -tdelta
1356-
13571356
# The following uses a mix of calls to relativedelta and timedelta
13581357
# methods because there is incomplete overlap in the functionality of
13591358
# these similar functions, and it's best to avoid doing our own math
@@ -1396,13 +1395,12 @@ def get_locator(self, dmin, dmax):
13961395
if num <= interval * (self.maxticks[freq] - 1):
13971396
break
13981397
else:
1399-
# We went through the whole loop without breaking, default to
1400-
# the last interval in the list and raise a warning
1401-
cbook._warn_external(
1402-
f"AutoDateLocator was unable to pick an appropriate "
1403-
f"interval for this date range. It may be necessary to "
1404-
f"add an interval value to the AutoDateLocator's "
1405-
f"intervald dictionary. Defaulting to {interval}.")
1398+
if not (self.interval_multiples and freq == DAILY):
1399+
cbook._warn_external(
1400+
f"AutoDateLocator was unable to pick an appropriate "
1401+
f"interval for this date range. It may be necessary "
1402+
f"to add an interval value to the AutoDateLocator's "
1403+
f"intervald dictionary. Defaulting to {interval}.")
14061404

14071405
# Set some parameters as appropriate
14081406
self._freq = freq

lib/matplotlib/tests/test_dates.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,11 @@ def _create_auto_date_locator(date1, date2):
398398
'1997-11-01 00:00:00+00:00', '1997-12-01 00:00:00+00:00']
399399
],
400400
[datetime.timedelta(days=141),
401-
['1997-01-01 00:00:00+00:00', '1997-01-22 00:00:00+00:00',
402-
'1997-02-01 00:00:00+00:00', '1997-02-22 00:00:00+00:00',
403-
'1997-03-01 00:00:00+00:00', '1997-03-22 00:00:00+00:00',
404-
'1997-04-01 00:00:00+00:00', '1997-04-22 00:00:00+00:00',
405-
'1997-05-01 00:00:00+00:00', '1997-05-22 00:00:00+00:00']
401+
['1997-01-01 00:00:00+00:00', '1997-01-15 00:00:00+00:00',
402+
'1997-02-01 00:00:00+00:00', '1997-02-15 00:00:00+00:00',
403+
'1997-03-01 00:00:00+00:00', '1997-03-15 00:00:00+00:00',
404+
'1997-04-01 00:00:00+00:00', '1997-04-15 00:00:00+00:00',
405+
'1997-05-01 00:00:00+00:00', '1997-05-15 00:00:00+00:00']
406406
],
407407
[datetime.timedelta(days=40),
408408
['1997-01-01 00:00:00+00:00', '1997-01-05 00:00:00+00:00',
@@ -471,8 +471,8 @@ def _create_auto_date_locator(date1, date2):
471471
'Sep', 'Oct', 'Nov', 'Dec']
472472
],
473473
[datetime.timedelta(days=141),
474-
['Jan', '22', 'Feb', '22', 'Mar', '22', 'Apr', '22',
475-
'May', '22']
474+
['Jan', '15', 'Feb', '15', 'Mar', '15', 'Apr', '15',
475+
'May', '15']
476476
],
477477
[datetime.timedelta(days=40),
478478
['Jan', '05', '09', '13', '17', '21', '25', '29', 'Feb',
@@ -523,8 +523,8 @@ def _create_auto_date_locator(date1, date2):
523523
'07/1997', '08/1997', '09/1997', '10/1997', '11/1997', '12/1997',
524524
]],
525525
[datetime.timedelta(days=141), [
526-
'01/1997', 'day: 22', '02/1997', 'day: 22', '03/1997', 'day: 22',
527-
'04/1997', 'day: 22', '05/1997', 'day: 22',
526+
'01/1997', 'day: 15', '02/1997', 'day: 15', '03/1997', 'day: 15',
527+
'04/1997', 'day: 15', '05/1997', 'day: 15',
528528
]],
529529
[datetime.timedelta(days=40), [
530530
'01/1997', 'day: 05', 'day: 09', 'day: 13', 'day: 17', 'day: 21',
@@ -578,8 +578,8 @@ def _create_auto_date_locator(date1, date2):
578578
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
579579
],
580580
[datetime.timedelta(days=141),
581-
['January', '22', 'February', '22', 'March',
582-
'22', 'April', '22', 'May', '22']
581+
['January', '15', 'February', '15', 'March',
582+
'15', 'April', '15', 'May', '15']
583583
],
584584
[datetime.timedelta(days=40),
585585
['January', '05', '09', '13', '17', '21',
@@ -671,11 +671,11 @@ def _create_auto_date_locator(date1, date2, tz):
671671
'1997-11-01 00:00:00-08:00', '1997-12-01 00:00:00-08:00']
672672
],
673673
[datetime.timedelta(days=141),
674-
['1997-01-01 00:00:00-08:00', '1997-01-22 00:00:00-08:00',
675-
'1997-02-01 00:00:00-08:00', '1997-02-22 00:00:00-08:00',
676-
'1997-03-01 00:00:00-08:00', '1997-03-22 00:00:00-08:00',
677-
'1997-04-01 00:00:00-08:00', '1997-04-22 00:00:00-07:00',
678-
'1997-05-01 00:00:00-07:00', '1997-05-22 00:00:00-07:00']
674+
['1997-01-01 00:00:00-08:00', '1997-01-15 00:00:00-08:00',
675+
'1997-02-01 00:00:00-08:00', '1997-02-15 00:00:00-08:00',
676+
'1997-03-01 00:00:00-08:00', '1997-03-15 00:00:00-08:00',
677+
'1997-04-01 00:00:00-08:00', '1997-04-15 00:00:00-07:00',
678+
'1997-05-01 00:00:00-07:00', '1997-05-15 00:00:00-07:00']
679679
],
680680
[datetime.timedelta(days=40),
681681
['1997-01-01 00:00:00-08:00', '1997-01-05 00:00:00-08:00',

0 commit comments

Comments
 (0)
0