|
46 | 46 | )
|
47 | 47 | from pandas.core.dtypes.generic import (
|
48 | 48 | ABCDataFrame,
|
| 49 | + ABCDatetimeIndex, |
49 | 50 | ABCIndex,
|
50 | 51 | ABCMultiIndex,
|
51 | 52 | ABCPeriodIndex,
|
52 | 53 | ABCSeries,
|
53 | 54 | )
|
54 |
| -from pandas.core.dtypes.missing import ( |
55 |
| - isna, |
56 |
| - notna, |
57 |
| -) |
| 55 | +from pandas.core.dtypes.missing import isna |
58 | 56 |
|
59 | 57 | import pandas.core.common as com
|
60 | 58 | from pandas.core.frame import DataFrame
|
|
95 | 93 | npt,
|
96 | 94 | )
|
97 | 95 |
|
98 |
| - from pandas import ( |
99 |
| - PeriodIndex, |
100 |
| - Series, |
101 |
| - ) |
| 96 | + from pandas import Series |
102 | 97 |
|
103 | 98 |
|
104 | 99 | def _color_in_style(style: str) -> bool:
|
@@ -888,26 +883,25 @@ def plt(self):
|
888 | 883 | _need_to_set_index = False
|
889 | 884 |
|
890 | 885 | @final
|
891 |
| - def _get_xticks(self, convert_period: bool = False): |
| 886 | + def _get_xticks(self): |
892 | 887 | index = self.data.index
|
893 | 888 | is_datetype = index.inferred_type in ("datetime", "date", "datetime64", "time")
|
894 | 889 |
|
895 | 890 | x: list[int] | np.ndarray
|
896 | 891 | if self.use_index:
|
897 |
| - if convert_period and isinstance(index, ABCPeriodIndex): |
898 |
| - self.data = self.data.reindex(index=index.sort_values()) |
899 |
| - index = cast("PeriodIndex", self.data.index) |
| 892 | + if isinstance(index, ABCPeriodIndex): |
| 893 | + # test_mixed_freq_irreg_period |
900 | 894 | x = index.to_timestamp()._mpl_repr()
|
| 895 | + # TODO: why do we need to do to_timestamp() here but not other |
| 896 | + # places where we call mpl_repr? |
901 | 897 | elif is_any_real_numeric_dtype(index.dtype):
|
902 | 898 | # Matplotlib supports numeric values or datetime objects as
|
903 | 899 | # xaxis values. Taking LBYL approach here, by the time
|
904 | 900 | # matplotlib raises exception when using non numeric/datetime
|
905 | 901 | # values for xaxis, several actions are already taken by plt.
|
906 | 902 | x = index._mpl_repr()
|
907 |
| - elif is_datetype: |
908 |
| - self.data = self.data[notna(self.data.index)] |
909 |
| - self.data = self.data.sort_index() |
910 |
| - x = self.data.index._mpl_repr() |
| 903 | + elif isinstance(index, ABCDatetimeIndex) or is_datetype: |
| 904 | + x = index._mpl_repr() |
911 | 905 | else:
|
912 | 906 | self._need_to_set_index = True
|
913 | 907 | x = list(range(len(index)))
|
@@ -1469,7 +1463,7 @@ def _make_plot(self, fig: Figure) -> None:
|
1469 | 1463 | plotf = self._ts_plot
|
1470 | 1464 | it = data.items()
|
1471 | 1465 | else:
|
1472 |
| - x = self._get_xticks(convert_period=True) |
| 1466 | + x = self._get_xticks() |
1473 | 1467 | # error: Incompatible types in assignment (expression has type
|
1474 | 1468 | # "Callable[[Any, Any, Any, Any, Any, Any, KwArg(Any)], Any]", variable has
|
1475 | 1469 | # type "Callable[[Any, Any, Any, Any, KwArg(Any)], Any]")
|
|
0 commit comments