|
9 | 9 | from pandas._libs import NaT, Timedelta, iNaT, join as libjoin, lib
|
10 | 10 | from pandas._libs.tslibs import BaseOffset, Resolution, Tick, timezones
|
11 | 11 | from pandas._libs.tslibs.parsing import DateParseError
|
12 |
| -from pandas._typing import Label |
| 12 | +from pandas._typing import Callable, Label |
13 | 13 | from pandas.compat.numpy import function as nv
|
14 | 14 | from pandas.errors import AbstractMethodError
|
15 | 15 | from pandas.util._decorators import Appender, cache_readonly, doc
|
@@ -338,6 +338,26 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs):
|
338 | 338 | # --------------------------------------------------------------------
|
339 | 339 | # Rendering Methods
|
340 | 340 |
|
| 341 | + def format( |
| 342 | + self, |
| 343 | + name: bool = False, |
| 344 | + formatter: Optional[Callable] = None, |
| 345 | + na_rep: str = "NaT", |
| 346 | + date_format: Optional[str] = None, |
| 347 | + ) -> List[str]: |
| 348 | + """ |
| 349 | + Render a string representation of the Index. |
| 350 | + """ |
| 351 | + header = [] |
| 352 | + if name: |
| 353 | + fmt_name = ibase.pprint_thing(self.name, escape_chars=("\t", "\r", "\n")) |
| 354 | + header.append(fmt_name) |
| 355 | + |
| 356 | + if formatter is not None: |
| 357 | + return header + list(self.map(formatter)) |
| 358 | + |
| 359 | + return self._format_with_header(header, na_rep=na_rep, date_format=date_format) |
| 360 | + |
341 | 361 | def _format_with_header(self, header, na_rep="NaT", date_format=None) -> List[str]:
|
342 | 362 | return header + list(
|
343 | 363 | self._format_native_types(na_rep=na_rep, date_format=date_format)
|
|
0 commit comments