|
11 | 11 | import numpy as np
|
12 | 12 |
|
13 | 13 | from pandas._libs import lib, tslibs
|
14 |
| -from pandas._libs.tslibs.frequencies import FreqGroup, get_freq_code, get_freq_group |
| 14 | +from pandas._libs.tslibs import to_offset |
| 15 | +from pandas._libs.tslibs.frequencies import FreqGroup, get_freq_group |
| 16 | +from pandas._libs.tslibs.offsets import BaseOffset |
15 | 17 |
|
16 | 18 | from pandas.core.dtypes.common import (
|
17 | 19 | is_datetime64_ns_dtype,
|
@@ -522,34 +524,36 @@ def has_level_label(label_flags, vmin):
|
522 | 524 | return True
|
523 | 525 |
|
524 | 526 |
|
525 |
| -def _daily_finder(vmin, vmax, freq): |
| 527 | +def _daily_finder(vmin, vmax, freq: BaseOffset): |
| 528 | + dtype_code = freq._period_dtype_code |
| 529 | + |
526 | 530 | periodsperday = -1
|
527 | 531 |
|
528 |
| - if freq >= FreqGroup.FR_HR: |
529 |
| - if freq == FreqGroup.FR_NS: |
| 532 | + if dtype_code >= FreqGroup.FR_HR: |
| 533 | + if dtype_code == FreqGroup.FR_NS: |
530 | 534 | periodsperday = 24 * 60 * 60 * 1000000000
|
531 |
| - elif freq == FreqGroup.FR_US: |
| 535 | + elif dtype_code == FreqGroup.FR_US: |
532 | 536 | periodsperday = 24 * 60 * 60 * 1000000
|
533 |
| - elif freq == FreqGroup.FR_MS: |
| 537 | + elif dtype_code == FreqGroup.FR_MS: |
534 | 538 | periodsperday = 24 * 60 * 60 * 1000
|
535 |
| - elif freq == FreqGroup.FR_SEC: |
| 539 | + elif dtype_code == FreqGroup.FR_SEC: |
536 | 540 | periodsperday = 24 * 60 * 60
|
537 |
| - elif freq == FreqGroup.FR_MIN: |
| 541 | + elif dtype_code == FreqGroup.FR_MIN: |
538 | 542 | periodsperday = 24 * 60
|
539 |
| - elif freq == FreqGroup.FR_HR: |
| 543 | + elif dtype_code == FreqGroup.FR_HR: |
540 | 544 | periodsperday = 24
|
541 | 545 | else: # pragma: no cover
|
542 |
| - raise ValueError(f"unexpected frequency: {freq}") |
| 546 | + raise ValueError(f"unexpected frequency: {dtype_code}") |
543 | 547 | periodsperyear = 365 * periodsperday
|
544 | 548 | periodspermonth = 28 * periodsperday
|
545 | 549 |
|
546 |
| - elif freq == FreqGroup.FR_BUS: |
| 550 | + elif dtype_code == FreqGroup.FR_BUS: |
547 | 551 | periodsperyear = 261
|
548 | 552 | periodspermonth = 19
|
549 |
| - elif freq == FreqGroup.FR_DAY: |
| 553 | + elif dtype_code == FreqGroup.FR_DAY: |
550 | 554 | periodsperyear = 365
|
551 | 555 | periodspermonth = 28
|
552 |
| - elif get_freq_group(freq) == FreqGroup.FR_WK: |
| 556 | + elif get_freq_group(dtype_code) == FreqGroup.FR_WK: |
553 | 557 | periodsperyear = 52
|
554 | 558 | periodspermonth = 3
|
555 | 559 | else: # pragma: no cover
|
@@ -676,7 +680,7 @@ def _second_finder(label_interval):
|
676 | 680 | elif span <= periodsperyear // 4:
|
677 | 681 | month_start = period_break(dates_, "month")
|
678 | 682 | info_maj[month_start] = True
|
679 |
| - if freq < FreqGroup.FR_HR: |
| 683 | + if dtype_code < FreqGroup.FR_HR: |
680 | 684 | info["min"] = True
|
681 | 685 | else:
|
682 | 686 | day_start = period_break(dates_, "day")
|
@@ -884,21 +888,20 @@ def _annual_finder(vmin, vmax, freq):
|
884 | 888 | return info
|
885 | 889 |
|
886 | 890 |
|
887 |
| -def get_finder(freq): |
888 |
| - if isinstance(freq, str): |
889 |
| - freq = get_freq_code(freq)[0] |
890 |
| - fgroup = get_freq_group(freq) |
| 891 | +def get_finder(freq: BaseOffset): |
| 892 | + dtype_code = freq._period_dtype_code |
| 893 | + fgroup = (dtype_code // 1000) * 1000 |
891 | 894 |
|
892 | 895 | if fgroup == FreqGroup.FR_ANN:
|
893 | 896 | return _annual_finder
|
894 | 897 | elif fgroup == FreqGroup.FR_QTR:
|
895 | 898 | return _quarterly_finder
|
896 |
| - elif freq == FreqGroup.FR_MTH: |
| 899 | + elif dtype_code == FreqGroup.FR_MTH: |
897 | 900 | return _monthly_finder
|
898 |
| - elif (freq >= FreqGroup.FR_BUS) or fgroup == FreqGroup.FR_WK: |
| 901 | + elif (dtype_code >= FreqGroup.FR_BUS) or fgroup == FreqGroup.FR_WK: |
899 | 902 | return _daily_finder
|
900 | 903 | else: # pragma: no cover
|
901 |
| - raise NotImplementedError(f"Unsupported frequency: {freq}") |
| 904 | + raise NotImplementedError(f"Unsupported frequency: {dtype_code}") |
902 | 905 |
|
903 | 906 |
|
904 | 907 | class TimeSeries_DateLocator(Locator):
|
@@ -930,8 +933,7 @@ def __init__(
|
930 | 933 | day=1,
|
931 | 934 | plot_obj=None,
|
932 | 935 | ):
|
933 |
| - if isinstance(freq, str): |
934 |
| - freq = get_freq_code(freq)[0] |
| 936 | + freq = to_offset(freq) |
935 | 937 | self.freq = freq
|
936 | 938 | self.base = base
|
937 | 939 | (self.quarter, self.month, self.day) = (quarter, month, day)
|
@@ -1009,8 +1011,7 @@ class TimeSeries_DateFormatter(Formatter):
|
1009 | 1011 | """
|
1010 | 1012 |
|
1011 | 1013 | def __init__(self, freq, minor_locator=False, dynamic_mode=True, plot_obj=None):
|
1012 |
| - if isinstance(freq, str): |
1013 |
| - freq = get_freq_code(freq)[0] |
| 1014 | + freq = to_offset(freq) |
1014 | 1015 | self.format = None
|
1015 | 1016 | self.freq = freq
|
1016 | 1017 | self.locs = []
|
|
0 commit comments