(ax: Axes, data: NDFrameT)
| 264 | |
| 265 | |
| 266 | def maybe_convert_index(ax: Axes, data: NDFrameT) -> NDFrameT: |
| 267 | # tsplot converts automatically, but don't want to convert index |
| 268 | # over and over for DataFrames |
| 269 | if isinstance(data.index, (ABCDatetimeIndex, ABCPeriodIndex)): |
| 270 | freq = _get_index_freq(data.index) |
| 271 | |
| 272 | if freq is None: |
| 273 | freq = _get_ax_freq(ax) |
| 274 | |
| 275 | if freq is None: |
| 276 | raise ValueError("Could not get frequency alias for plotting") |
| 277 | |
| 278 | freq_str = _get_period_alias(freq) |
| 279 | |
| 280 | with warnings.catch_warnings(): |
| 281 | # suppress Period[B] deprecation warning |
| 282 | # TODO: need to find an alternative to this before the deprecation |
| 283 | # is enforced! |
| 284 | warnings.filterwarnings( |
| 285 | "ignore", |
| 286 | r"PeriodDtype\[B\] is deprecated", |
| 287 | category=FutureWarning, |
| 288 | ) |
| 289 | |
| 290 | if isinstance(data.index, ABCDatetimeIndex): |
| 291 | data = data.tz_localize(None).to_period(freq=freq_str) |
| 292 | elif isinstance(data.index, ABCPeriodIndex): |
| 293 | data.index = data.index.asfreq(freq=freq_str, how="start") |
| 294 | return data |
| 295 | |
| 296 | |
| 297 | # Patch methods for subplot. |
no test coverage detected