Skip to content

Commit fa96a52

Browse files
authored
REF: remove redundant Index formatting methods (#55432)
* REF: remove IntervalIndex._format_data, _format_space * improve check, remove outdated comment
1 parent 69cd075 commit fa96a52

File tree

3 files changed

+3
-26
lines changed

3 files changed

+3
-26
lines changed

pandas/core/arrays/interval.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,6 @@ def value_counts(self, dropna: bool = True) -> Series:
12351235

12361236
def _format_data(self) -> str:
12371237
# TODO: integrate with categorical and make generic
1238-
# name argument is unused here; just for compat with base / categorical
12391238
n = len(self)
12401239
max_seq_items = min((get_option("display.max_seq_items") or n) // 10, 10)
12411240

@@ -1266,19 +1265,12 @@ def _format_data(self) -> str:
12661265
return summary
12671266

12681267
def __repr__(self) -> str:
1269-
# the short repr has no trailing newline, while the truncated
1270-
# repr does. So we include a newline in our template, and strip
1271-
# any trailing newlines from format_object_summary
12721268
data = self._format_data()
12731269
class_name = f"<{type(self).__name__}>\n"
12741270

12751271
template = f"{class_name}{data}\nLength: {len(self)}, dtype: {self.dtype}"
12761272
return template
12771273

1278-
def _format_space(self) -> str:
1279-
space = " " * (len(type(self).__name__) + 1)
1280-
return f"\n{space}"
1281-
12821274
# ---------------------------------------------------------------------
12831275
# Vectorized Interval Properties/Attributes
12841276

pandas/core/indexes/base.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,25 +1284,16 @@ def __repr__(self) -> str_t:
12841284
klass_name = type(self).__name__
12851285
data = self._format_data()
12861286
attrs = self._format_attrs()
1287-
space = self._format_space()
12881287
attrs_str = [f"{k}={v}" for k, v in attrs]
1289-
prepr = f",{space}".join(attrs_str)
1288+
prepr = ", ".join(attrs_str)
12901289

12911290
# no data provided, just attributes
12921291
if data is None:
1292+
# i.e. RangeIndex
12931293
data = ""
12941294

12951295
return f"{klass_name}({data}{prepr})"
12961296

1297-
def _format_space(self) -> str_t:
1298-
# using space here controls if the attributes
1299-
# are line separated or not (the default)
1300-
1301-
# max_seq_items = get_option('display.max_seq_items')
1302-
# if len(self) > max_seq_items:
1303-
# space = "\n%s" % (' ' * (len(klass) + 1))
1304-
return " "
1305-
13061297
@property
13071298
def _formatter_func(self):
13081299
"""
@@ -1319,7 +1310,7 @@ def _format_data(self, name=None) -> str_t:
13191310

13201311
if self.inferred_type == "string":
13211312
is_justify = False
1322-
elif self.inferred_type == "categorical":
1313+
elif isinstance(self.dtype, CategoricalDtype):
13231314
self = cast("CategoricalIndex", self)
13241315
if is_object_dtype(self.categories.dtype):
13251316
is_justify = False

pandas/core/indexes/interval.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -844,17 +844,11 @@ def length(self) -> Index:
844844

845845
# --------------------------------------------------------------------
846846
# Rendering Methods
847-
# __repr__ associated methods are based on MultiIndex
848847

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

853-
def _format_data(self, name=None) -> str:
854-
# TODO: integrate with categorical and make generic
855-
# name argument is unused here; just for compat with base / categorical
856-
return f"{self._data._format_data()},{self._format_space()}"
857-
858852
# --------------------------------------------------------------------
859853
# Set Operations
860854

0 commit comments

Comments
 (0)