MCPcopy
hub / github.com/pandas-dev/pandas / format_object_summary

Function format_object_summary

pandas/io/formats/printing.py:300–468  ·  view source on GitHub ↗

Return the formatted obj as a unicode string Parameters ---------- obj : object must be iterable and support __getitem__ formatter : callable string formatter for an element is_justify : bool should justify the display name : name, optional

(
    obj: ListLike,
    formatter: Callable,
    is_justify: bool = True,
    name: str | None = None,
    indent_for_name: bool = True,
    line_break_each_value: bool = False,
)

Source from the content-addressed store, hash-verified

298
299
300def format_object_summary(
301 obj: ListLike,
302 formatter: Callable,
303 is_justify: bool = True,
304 name: str | None = None,
305 indent_for_name: bool = True,
306 line_break_each_value: bool = False,
307) -> str:
308 """
309 Return the formatted obj as a unicode string
310
311 Parameters
312 ----------
313 obj : object
314 must be iterable and support __getitem__
315 formatter : callable
316 string formatter for an element
317 is_justify : bool
318 should justify the display
319 name : name, optional
320 defaults to the class name of the obj
321 indent_for_name : bool, default True
322 Whether subsequent lines should be indented to
323 align with the name.
324 line_break_each_value : bool, default False
325 If True, inserts a line break for each value of ``obj``.
326 If False, only break lines when the a line of values gets wider
327 than the display width.
328
329 Returns
330 -------
331 summary string
332 """
333 display_width, _ = get_console_size()
334 if display_width is None:
335 display_width = get_option("display.width") or 80
336 if name is None:
337 name = type(obj).__name__
338
339 if indent_for_name:
340 name_len = len(name)
341 space1 = f"\n{(' ' * (name_len + 1))}"
342 space2 = f"\n{(' ' * (name_len + 2))}"
343 else:
344 space1 = "\n"
345 space2 = "\n " # space for the opening '['
346
347 n = len(obj)
348 if line_break_each_value:
349 # If we want to vertically align on each value of obj, we need to
350 # separate values by a line break and indent the values
351 sep = ",\n " + " " * len(name)
352 else:
353 sep = ","
354 max_seq_items = get_option("display.max_seq_items") or n
355
356 # are we a truncated display
357 is_truncated = n > max_seq_items

Callers 3

__repr__Method · 0.90
_repr_2dMethod · 0.90
_format_dataMethod · 0.90

Calls 12

get_console_sizeFunction · 0.90
get_optionFunction · 0.90
get_adjustmentFunction · 0.85
minFunction · 0.85
_justifyFunction · 0.85
maxFunction · 0.85
best_lenFunction · 0.85
_pprint_seqFunction · 0.85
_extend_lineFunction · 0.85
rjustMethod · 0.80
rstripMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected