Skip to content

Commit 992d579

Browse files
author
gcerri
committed
Adding doc and fix typing
1 parent 35a5842 commit 992d579

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

pandas/io/formats/info.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@
5454
)
5555

5656

57+
return_dict_sub = dedent(
58+
"""\
59+
return_dict : bool, optional
60+
Whether to return the summary as a dictionary. If True, the method
61+
returns a dictionary containing information about the DataFrame.
62+
If False, the summary is printed and None is returned."""
63+
)
64+
65+
5766
frame_examples_sub = dedent(
5867
"""\
5968
>>> int_values = [1, 2, 3, 4, 5]
@@ -136,7 +145,11 @@
136145
1 column_2 1000000 non-null object
137146
2 column_3 1000000 non-null object
138147
dtypes: object(3)
139-
memory usage: 165.9 MB"""
148+
memory usage: 165.9 MB
149+
150+
>>> info_dict = df.info(return_dict=True)
151+
>>> print(info_dict)
152+
{'Column_summary': '...', 'Memory_usage': 24000128, 'Index_type': 'RangeIndex', 'Index_entries': 1000000}"""
140153
)
141154

142155

@@ -153,6 +166,7 @@
153166
"type_sub": " and columns",
154167
"max_cols_sub": frame_max_cols_sub,
155168
"show_counts_sub": show_counts_sub,
169+
"return_dict_sub": return_dict_sub,
156170
"examples_sub": frame_examples_sub,
157171
"see_also_sub": frame_see_also_sub,
158172
"version_added_sub": "",
@@ -233,6 +247,7 @@
233247
"type_sub": "",
234248
"max_cols_sub": "",
235249
"show_counts_sub": show_counts_sub,
250+
"return_dict_sub": return_dict_sub,
236251
"examples_sub": series_examples_sub,
237252
"see_also_sub": series_see_also_sub,
238253
"version_added_sub": "\n.. versionadded:: 1.4.0\n",
@@ -273,11 +288,13 @@
273288
:ref:`Frequently Asked Questions <df-memory-usage>` for more
274289
details.
275290
{show_counts_sub}
276-
291+
{return_dict_sub}
292+
277293
Returns
278294
-------
279-
None
280-
This method prints a summary of a {klass} and returns None.
295+
dict or None
296+
If return_dict is True, returns a dictionary summarizing the {klass}.
297+
Otherwise, returns None.
281298
282299
See Also
283300
--------
@@ -435,7 +452,7 @@ def render(
435452
max_cols: int | None,
436453
verbose: bool | None,
437454
show_counts: bool | None,
438-
) -> None:
455+
) -> None | dict:
439456
pass
440457

441458

@@ -524,7 +541,7 @@ def render(
524541
verbose: bool | None,
525542
show_counts: bool | None,
526543
return_dict: bool | None,
527-
) -> None:
544+
) -> None | dict:
528545
if return_dict:
529546
return self.to_dict()
530547
else:

0 commit comments

Comments
 (0)