|
14 | 14 | Final, |
15 | 15 | cast, |
16 | 16 | ) |
| 17 | +import warnings |
17 | 18 |
|
18 | 19 | import matplotlib.dates as mdates |
19 | 20 | from matplotlib.ticker import ( |
@@ -243,18 +244,29 @@ def _convert_1d(values, units, axis): |
243 | 244 | if not hasattr(axis, "freq"): |
244 | 245 | raise TypeError("Axis must have `freq` set to convert to Periods") |
245 | 246 | valid_types = (str, datetime, Period, pydt.date, pydt.time, np.datetime64) |
246 | | - if isinstance(values, valid_types) or is_integer(values) or is_float(values): |
247 | | - return get_datevalue(values, axis.freq) |
248 | | - elif isinstance(values, PeriodIndex): |
249 | | - return values.asfreq(axis.freq).asi8 |
250 | | - elif isinstance(values, Index): |
251 | | - return values.map(lambda x: get_datevalue(x, axis.freq)) |
252 | | - elif lib.infer_dtype(values, skipna=False) == "period": |
253 | | - # https://github.com/pandas-dev/pandas/issues/24304 |
254 | | - # convert ndarray[period] -> PeriodIndex |
255 | | - return PeriodIndex(values, freq=axis.freq).asi8 |
256 | | - elif isinstance(values, (list, tuple, np.ndarray, Index)): |
257 | | - return [get_datevalue(x, axis.freq) for x in values] |
| 247 | + with warnings.catch_warnings(): |
| 248 | + warnings.filterwarnings( |
| 249 | + "ignore", "Period with BDay freq is deprecated", category=FutureWarning |
| 250 | + ) |
| 251 | + warnings.filterwarnings( |
| 252 | + "ignore", r"PeriodDtype\[B\] is deprecated", category=FutureWarning |
| 253 | + ) |
| 254 | + if ( |
| 255 | + isinstance(values, valid_types) |
| 256 | + or is_integer(values) |
| 257 | + or is_float(values) |
| 258 | + ): |
| 259 | + return get_datevalue(values, axis.freq) |
| 260 | + elif isinstance(values, PeriodIndex): |
| 261 | + return values.asfreq(axis.freq).asi8 |
| 262 | + elif isinstance(values, Index): |
| 263 | + return values.map(lambda x: get_datevalue(x, axis.freq)) |
| 264 | + elif lib.infer_dtype(values, skipna=False) == "period": |
| 265 | + # https://github.com/pandas-dev/pandas/issues/24304 |
| 266 | + # convert ndarray[period] -> PeriodIndex |
| 267 | + return PeriodIndex(values, freq=axis.freq).asi8 |
| 268 | + elif isinstance(values, (list, tuple, np.ndarray, Index)): |
| 269 | + return [get_datevalue(x, axis.freq) for x in values] |
258 | 270 | return values |
259 | 271 |
|
260 | 272 |
|
@@ -567,14 +579,30 @@ def _daily_finder(vmin, vmax, freq: BaseOffset): |
567 | 579 | # save this for later usage |
568 | 580 | vmin_orig = vmin |
569 | 581 |
|
570 | | - (vmin, vmax) = ( |
571 | | - Period(ordinal=int(vmin), freq=freq), |
572 | | - Period(ordinal=int(vmax), freq=freq), |
573 | | - ) |
| 582 | + with warnings.catch_warnings(): |
| 583 | + warnings.filterwarnings( |
| 584 | + "ignore", "Period with BDay freq is deprecated", category=FutureWarning |
| 585 | + ) |
| 586 | + warnings.filterwarnings( |
| 587 | + "ignore", r"PeriodDtype\[B\] is deprecated", category=FutureWarning |
| 588 | + ) |
| 589 | + (vmin, vmax) = ( |
| 590 | + Period(ordinal=int(vmin), freq=freq), |
| 591 | + Period(ordinal=int(vmax), freq=freq), |
| 592 | + ) |
574 | 593 | assert isinstance(vmin, Period) |
575 | 594 | assert isinstance(vmax, Period) |
576 | 595 | span = vmax.ordinal - vmin.ordinal + 1 |
577 | | - dates_ = period_range(start=vmin, end=vmax, freq=freq) |
| 596 | + |
| 597 | + with warnings.catch_warnings(): |
| 598 | + warnings.filterwarnings( |
| 599 | + "ignore", "Period with BDay freq is deprecated", category=FutureWarning |
| 600 | + ) |
| 601 | + warnings.filterwarnings( |
| 602 | + "ignore", r"PeriodDtype\[B\] is deprecated", category=FutureWarning |
| 603 | + ) |
| 604 | + dates_ = period_range(start=vmin, end=vmax, freq=freq) |
| 605 | + |
578 | 606 | # Initialize the output |
579 | 607 | info = np.zeros( |
580 | 608 | span, dtype=[("val", np.int64), ("maj", bool), ("min", bool), ("fmt", "|S20")] |
@@ -1072,7 +1100,13 @@ def __call__(self, x, pos: int = 0) -> str: |
1072 | 1100 | fmt = self.formatdict.pop(x, "") |
1073 | 1101 | if isinstance(fmt, np.bytes_): |
1074 | 1102 | fmt = fmt.decode("utf-8") |
1075 | | - period = Period(ordinal=int(x), freq=self.freq) |
| 1103 | + with warnings.catch_warnings(): |
| 1104 | + warnings.filterwarnings( |
| 1105 | + "ignore", |
| 1106 | + "Period with BDay freq is deprecated", |
| 1107 | + category=FutureWarning, |
| 1108 | + ) |
| 1109 | + period = Period(ordinal=int(x), freq=self.freq) |
1076 | 1110 | assert isinstance(period, Period) |
1077 | 1111 | return period.strftime(fmt) |
1078 | 1112 |
|
|
0 commit comments