Skip to content

Commit c18ae3b

Browse files
authored
REF: remove unnecessary IntervalIndex._format_native_types (#55416)
* REF: make _format_with_header keyword-only * REF: remove IntervalIndex._format_native_types
1 parent 494df5c commit c18ae3b

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

pandas/core/indexes/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,9 +1390,9 @@ def format(
13901390
if formatter is not None:
13911391
return header + list(self.map(formatter))
13921392

1393-
return self._format_with_header(header, na_rep=na_rep)
1393+
return self._format_with_header(header=header, na_rep=na_rep)
13941394

1395-
def _format_with_header(self, header: list[str_t], na_rep: str_t) -> list[str_t]:
1395+
def _format_with_header(self, *, header: list[str_t], na_rep: str_t) -> list[str_t]:
13961396
from pandas.io.formats.format import format_array
13971397

13981398
values = self._values

pandas/core/indexes/category.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def _format_attrs(self):
356356
extra = super()._format_attrs()
357357
return attrs + extra
358358

359-
def _format_with_header(self, header: list[str], na_rep: str) -> list[str]:
359+
def _format_with_header(self, *, header: list[str], na_rep: str) -> list[str]:
360360
result = [
361361
pprint_thing(x, escape_chars=("\t", "\r", "\n")) if notna(x) else na_rep
362362
for x in self._values

pandas/core/indexes/datetimelike.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,12 @@ def format(
209209
if formatter is not None:
210210
return header + list(self.map(formatter))
211211

212-
return self._format_with_header(header, na_rep=na_rep, date_format=date_format)
212+
return self._format_with_header(
213+
header=header, na_rep=na_rep, date_format=date_format
214+
)
213215

214216
def _format_with_header(
215-
self, header: list[str], na_rep: str = "NaT", date_format: str | None = None
217+
self, *, header: list[str], na_rep: str, date_format: str | None = None
216218
) -> list[str]:
217219
# matches base class except for whitespace padding and date_format
218220
return header + list(

pandas/core/indexes/interval.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -846,16 +846,10 @@ def length(self) -> Index:
846846
# Rendering Methods
847847
# __repr__ associated methods are based on MultiIndex
848848

849-
def _format_with_header(self, header: list[str], na_rep: str) -> list[str]:
849+
def _format_with_header(self, *, header: list[str], na_rep: str) -> list[str]:
850850
# matches base class except for whitespace padding
851851
return header + list(self._format_native_types(na_rep=na_rep))
852852

853-
def _format_native_types(
854-
self, *, na_rep: str = "NaN", quoting=None, **kwargs
855-
) -> npt.NDArray[np.object_]:
856-
# GH 28210: use base method but with different default na_rep
857-
return super()._format_native_types(na_rep=na_rep, quoting=quoting, **kwargs)
858-
859853
def _format_data(self, name=None) -> str:
860854
# TODO: integrate with categorical and make generic
861855
# name argument is unused here; just for compat with base / categorical

pandas/core/indexes/range.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def _format_data(self, name=None):
266266
# we are formatting thru the attributes
267267
return None
268268

269-
def _format_with_header(self, header: list[str], na_rep: str) -> list[str]:
269+
def _format_with_header(self, *, header: list[str], na_rep: str) -> list[str]:
270270
# Equivalent to Index implementation, but faster
271271
if not len(self._range):
272272
return header

pandas/tests/indexes/interval/test_formats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_repr_floats(self):
104104
def test_to_native_types(self, tuples, closed, expected_data):
105105
# GH 28210
106106
index = IntervalIndex.from_tuples(tuples, closed=closed)
107-
result = index._format_native_types()
107+
result = index._format_native_types(na_rep="NaN")
108108
expected = np.array(expected_data)
109109
tm.assert_numpy_array_equal(result, expected)
110110

0 commit comments

Comments
 (0)