Skip to content
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

REF: remove unnecessary IntervalIndex._format_native_types #55416

Merged
merged 2 commits into from
Oct 6, 2023
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
4 changes: 2 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1390,9 +1390,9 @@ def format(
if formatter is not None:
return header + list(self.map(formatter))

return self._format_with_header(header, na_rep=na_rep)
return self._format_with_header(header=header, na_rep=na_rep)

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

values = self._values
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def _format_attrs(self):
extra = super()._format_attrs()
return attrs + extra

def _format_with_header(self, header: list[str], na_rep: str) -> list[str]:
def _format_with_header(self, *, header: list[str], na_rep: str) -> list[str]:
result = [
pprint_thing(x, escape_chars=("\t", "\r", "\n")) if notna(x) else na_rep
for x in self._values
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ def format(
if formatter is not None:
return header + list(self.map(formatter))

return self._format_with_header(header, na_rep=na_rep, date_format=date_format)
return self._format_with_header(
header=header, na_rep=na_rep, date_format=date_format
)

def _format_with_header(
self, header: list[str], na_rep: str = "NaT", date_format: str | None = None
self, *, header: list[str], na_rep: str, date_format: str | None = None
) -> list[str]:
# matches base class except for whitespace padding and date_format
return header + list(
Expand Down
8 changes: 1 addition & 7 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,16 +846,10 @@ def length(self) -> Index:
# Rendering Methods
# __repr__ associated methods are based on MultiIndex

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

def _format_native_types(
self, *, na_rep: str = "NaN", quoting=None, **kwargs
) -> npt.NDArray[np.object_]:
# GH 28210: use base method but with different default na_rep
return super()._format_native_types(na_rep=na_rep, quoting=quoting, **kwargs)

def _format_data(self, name=None) -> str:
# TODO: integrate with categorical and make generic
# name argument is unused here; just for compat with base / categorical
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def _format_data(self, name=None):
# we are formatting thru the attributes
return None

def _format_with_header(self, header: list[str], na_rep: str) -> list[str]:
def _format_with_header(self, *, header: list[str], na_rep: str) -> list[str]:
# Equivalent to Index implementation, but faster
if not len(self._range):
return header
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/interval/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_repr_floats(self):
def test_to_native_types(self, tuples, closed, expected_data):
# GH 28210
index = IntervalIndex.from_tuples(tuples, closed=closed)
result = index._format_native_types()
result = index._format_native_types(na_rep="NaN")
expected = np.array(expected_data)
tm.assert_numpy_array_equal(result, expected)

Expand Down
Loading