Skip to content

Commit 140802a

Browse files
authored
REF: share _mpl_repr (#41627)
1 parent 59024aa commit 140802a

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

pandas/core/indexes/base.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,12 @@ def _format_attrs(self) -> list[tuple[str_t, str_t | int]]:
11721172
"""
11731173
return format_object_attrs(self, include_dtype=not self._is_multi)
11741174

1175-
def _mpl_repr(self):
1175+
@final
1176+
def _mpl_repr(self) -> np.ndarray:
11761177
# how to represent ourselves to matplotlib
1177-
return self.values
1178+
if isinstance(self.dtype, np.dtype) and self.dtype.kind != "M":
1179+
return cast(np.ndarray, self.values)
1180+
return self.astype(object, copy=False)._values
11781181

11791182
def format(
11801183
self,

pandas/core/indexes/datetimes.py

-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
)
2626
from pandas._libs.tslibs import (
2727
Resolution,
28-
ints_to_pydatetime,
2928
parsing,
3029
timezones,
3130
to_offset,
@@ -392,10 +391,6 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
392391
# --------------------------------------------------------------------
393392
# Rendering Methods
394393

395-
def _mpl_repr(self) -> np.ndarray:
396-
# how to represent ourselves to matplotlib
397-
return ints_to_pydatetime(self.asi8, self.tz)
398-
399394
@property
400395
def _formatter_func(self):
401396
from pandas.io.formats.format import get_format_datetime64

pandas/core/indexes/period.py

-7
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,6 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
321321
return False
322322
return dtype.freq == self.freq
323323

324-
# ------------------------------------------------------------------------
325-
# Rendering Methods
326-
327-
def _mpl_repr(self) -> np.ndarray:
328-
# how to represent ourselves to matplotlib
329-
return self.astype(object)._values
330-
331324
# ------------------------------------------------------------------------
332325
# Indexing
333326

0 commit comments

Comments
 (0)