Pick the best locator based on a distance.
(self, dmin, dmax)
| 1346 | return RRuleLocator.get_unit_generic(self._freq) |
| 1347 | |
| 1348 | def get_locator(self, dmin, dmax): |
| 1349 | """Pick the best locator based on a distance.""" |
| 1350 | delta = relativedelta(dmax, dmin) |
| 1351 | tdelta = dmax - dmin |
| 1352 | |
| 1353 | # take absolute difference |
| 1354 | if dmin > dmax: |
| 1355 | delta = -delta |
| 1356 | tdelta = -tdelta |
| 1357 | # The following uses a mix of calls to relativedelta and timedelta |
| 1358 | # methods because there is incomplete overlap in the functionality of |
| 1359 | # these similar functions, and it's best to avoid doing our own math |
| 1360 | # whenever possible. |
| 1361 | numYears = float(delta.years) |
| 1362 | numMonths = numYears * MONTHS_PER_YEAR + delta.months |
| 1363 | numDays = tdelta.days # Avoids estimates of days/month, days/year. |
| 1364 | numHours = numDays * HOURS_PER_DAY + delta.hours |
| 1365 | numMinutes = numHours * MIN_PER_HOUR + delta.minutes |
| 1366 | numSeconds = np.floor(tdelta.total_seconds()) |
| 1367 | numMicroseconds = np.floor(tdelta.total_seconds() * 1e6) |
| 1368 | |
| 1369 | nums = [numYears, numMonths, numDays, numHours, numMinutes, |
| 1370 | numSeconds, numMicroseconds] |
| 1371 | |
| 1372 | use_rrule_locator = [True] * 6 + [False] |
| 1373 | |
| 1374 | # Default setting of bymonth, etc. to pass to rrule |
| 1375 | # [unused (for year), bymonth, bymonthday, byhour, byminute, |
| 1376 | # bysecond, unused (for microseconds)] |
| 1377 | byranges = [None, 1, 1, 0, 0, 0, None] |
| 1378 | |
| 1379 | # Loop over all the frequencies and try to find one that gives at |
| 1380 | # least a minticks tick positions. Once this is found, look for |
| 1381 | # an interval from a list specific to that frequency that gives no |
| 1382 | # more than maxticks tick positions. Also, set up some ranges |
| 1383 | # (bymonth, etc.) as appropriate to be passed to rrulewrapper. |
| 1384 | for i, (freq, num) in enumerate(zip(self._freqs, nums)): |
| 1385 | # If this particular frequency doesn't give enough ticks, continue |
| 1386 | if num < self.minticks: |
| 1387 | # Since we're not using this particular frequency, set |
| 1388 | # the corresponding by_ to None so the rrule can act as |
| 1389 | # appropriate |
| 1390 | byranges[i] = None |
| 1391 | continue |
| 1392 | |
| 1393 | # Find the first available interval that doesn't give too many |
| 1394 | # ticks |
| 1395 | for interval in self.intervald[freq]: |
| 1396 | if num <= interval * (self.maxticks[freq] - 1): |
| 1397 | break |
| 1398 | else: |
| 1399 | if not (self.interval_multiples and freq == DAILY): |
| 1400 | _api.warn_external( |
| 1401 | f"AutoDateLocator was unable to pick an appropriate " |
| 1402 | f"interval for this date range. It may be necessary " |
| 1403 | f"to add an interval value to the AutoDateLocator's " |
| 1404 | f"intervald dictionary. Defaulting to {interval}.") |
| 1405 |
nothing calls this directly