Skip to content

Commit 7854a1c

Browse files
committed
CLN: remove kwargs in Index.format
1 parent 7e25af8 commit 7854a1c

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

pandas/core/indexes/base.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
from datetime import datetime
33
import operator
44
from textwrap import dedent
5-
from typing import TYPE_CHECKING, Any, Callable, FrozenSet, Hashable, Optional, Union
5+
from typing import (
6+
TYPE_CHECKING,
7+
Any,
8+
Callable,
9+
FrozenSet,
10+
Hashable,
11+
Optional,
12+
Union,
13+
List,
14+
)
615
import warnings
716

817
import numpy as np
@@ -893,7 +902,7 @@ def _mpl_repr(self):
893902
# how to represent ourselves to matplotlib
894903
return self.values
895904

896-
def format(self, name: bool = False, formatter=None, **kwargs):
905+
def format(self, name: bool = False, formatter=None, na_rep="NaN") -> List[str_t]:
897906
"""
898907
Render a string representation of the Index.
899908
"""
@@ -908,9 +917,9 @@ def format(self, name: bool = False, formatter=None, **kwargs):
908917
if formatter is not None:
909918
return header + list(self.map(formatter))
910919

911-
return self._format_with_header(header, **kwargs)
920+
return self._format_with_header(header, na_rep=na_rep)
912921

913-
def _format_with_header(self, header, na_rep="NaN", **kwargs):
922+
def _format_with_header(self, header, na_rep, **kwargs):
914923
values = self._values
915924

916925
from pandas.io.formats.format import format_array

pandas/core/indexes/datetimelike.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,23 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs):
338338
# --------------------------------------------------------------------
339339
# Rendering Methods
340340

341-
def _format_with_header(self, header, na_rep="NaT", **kwargs):
341+
def format(
342+
self, name: bool = False, formatter=None, date_format=None, na_rep="NaT"
343+
) -> List[str]:
344+
"""
345+
Render a string representation of the Index.
346+
"""
347+
header = []
348+
if name:
349+
fmt_name = ibase.pprint_thing(self.name, escape_chars=("\t", "\r", "\n"))
350+
header.append(fmt_name)
351+
352+
if formatter is not None:
353+
return header + list(self.map(formatter))
354+
355+
return self._format_with_header(header, date_format=date_format, na_rep=na_rep)
356+
357+
def _format_with_header(self, header, na_rep, **kwargs):
342358
return header + list(self._format_native_types(na_rep, **kwargs))
343359

344360
@property

pandas/core/indexes/multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ def format(
12371237
names=False,
12381238
na_rep=None,
12391239
formatter=None,
1240-
):
1240+
) -> list:
12411241
if len(self) == 0:
12421242
return []
12431243

pandas/core/indexes/range.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ def _format_data(self, name=None):
197197
# we are formatting thru the attributes
198198
return None
199199

200-
def _format_with_header(self, header, na_rep="NaN", **kwargs):
201-
return header + list(map(pprint_thing, self._range))
200+
def _format_with_header(self, header, na_rep, **kwargs):
201+
return header + [pprint_thing(x) for x in self._range]
202202

203203
# --------------------------------------------------------------------
204204
_deprecation_message = (

pandas/io/formats/style.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,10 @@ def _get_level_lengths(index, hidden_elements=None):
15241524
15251525
Result is a dictionary of (level, initial_position): span
15261526
"""
1527-
levels = index.format(sparsify=lib.no_default, adjoin=False, names=False)
1527+
if isinstance(index, pd.MultiIndex):
1528+
levels = index.format(sparsify=lib.no_default, adjoin=False)
1529+
else:
1530+
levels = index.format()
15281531

15291532
if hidden_elements is None:
15301533
hidden_elements = []

0 commit comments

Comments
 (0)