Skip to content

Commit 1025151

Browse files
authored
REF: de-duplicate IntervalArray formatting functions (#55469)
1 parent f7b49d8 commit 1025151

File tree

1 file changed

+4
-39
lines changed

1 file changed

+4
-39
lines changed

pandas/core/arrays/interval.py

+4-39
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
import numpy as np
1717

18-
from pandas._config import get_option
19-
2018
from pandas._libs import lib
2119
from pandas._libs.interval import (
2220
VALID_CLOSED,
@@ -1233,43 +1231,10 @@ def value_counts(self, dropna: bool = True) -> Series:
12331231
# ---------------------------------------------------------------------
12341232
# Rendering Methods
12351233

1236-
def _format_data(self) -> str:
1237-
# TODO: integrate with categorical and make generic
1238-
n = len(self)
1239-
max_seq_items = min((get_option("display.max_seq_items") or n) // 10, 10)
1240-
1241-
formatter = str
1242-
1243-
if n == 0:
1244-
summary = "[]"
1245-
elif n == 1:
1246-
first = formatter(self[0])
1247-
summary = f"[{first}]"
1248-
elif n == 2:
1249-
first = formatter(self[0])
1250-
last = formatter(self[-1])
1251-
summary = f"[{first}, {last}]"
1252-
else:
1253-
if n > max_seq_items:
1254-
n = min(max_seq_items // 2, 10)
1255-
head = [formatter(x) for x in self[:n]]
1256-
tail = [formatter(x) for x in self[-n:]]
1257-
head_str = ", ".join(head)
1258-
tail_str = ", ".join(tail)
1259-
summary = f"[{head_str} ... {tail_str}]"
1260-
else:
1261-
tail = [formatter(x) for x in self]
1262-
tail_str = ", ".join(tail)
1263-
summary = f"[{tail_str}]"
1264-
1265-
return summary
1266-
1267-
def __repr__(self) -> str:
1268-
data = self._format_data()
1269-
class_name = f"<{type(self).__name__}>\n"
1270-
1271-
template = f"{class_name}{data}\nLength: {len(self)}, dtype: {self.dtype}"
1272-
return template
1234+
def _formatter(self, boxed: bool = False):
1235+
# returning 'str' here causes us to render as e.g. "(0, 1]" instead of
1236+
# "Interval(0, 1, closed='right')"
1237+
return str
12731238

12741239
# ---------------------------------------------------------------------
12751240
# Vectorized Interval Properties/Attributes

0 commit comments

Comments
 (0)