Skip to content

REF: share _mpl_repr #41627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,9 +1167,12 @@ def _format_attrs(self):
"""
return format_object_attrs(self)

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

def format(
self,
Expand Down
5 changes: 0 additions & 5 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
)
from pandas._libs.tslibs import (
Resolution,
ints_to_pydatetime,
parsing,
timezones,
to_offset,
Expand Down Expand Up @@ -392,10 +391,6 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
# --------------------------------------------------------------------
# Rendering Methods

def _mpl_repr(self) -> np.ndarray:
# how to represent ourselves to matplotlib
return ints_to_pydatetime(self.asi8, self.tz)

@property
def _formatter_func(self):
from pandas.io.formats.format import get_format_datetime64
Expand Down
7 changes: 0 additions & 7 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,6 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
return False
return dtype.freq == self.freq

# ------------------------------------------------------------------------
# Rendering Methods

def _mpl_repr(self) -> np.ndarray:
# how to represent ourselves to matplotlib
return self.astype(object)._values

# ------------------------------------------------------------------------
# Indexing

Expand Down