Skip to content

Commit 8ceb0e1

Browse files
committed
Extract INFO_DOCSTRING to fix doc decorator
1 parent 751143c commit 8ceb0e1

File tree

2 files changed

+78
-50
lines changed

2 files changed

+78
-50
lines changed

pandas/core/frame.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@
201201
console,
202202
format as fmt,
203203
)
204-
from pandas.io.formats.info import DataFrameInfo
204+
from pandas.io.formats.info import (
205+
DataFrameInfo,
206+
frame_sub_kwargs,
207+
)
205208
import pandas.plotting
206209

207210
if TYPE_CHECKING:
@@ -3000,7 +3003,7 @@ def to_xml(
30003003
return xml_formatter.write_output()
30013004

30023005
# ----------------------------------------------------------------------
3003-
@doc(DataFrameInfo.render)
3006+
@doc(DataFrameInfo.render, **frame_sub_kwargs)
30043007
def info(
30053008
self,
30063009
verbose: bool | None = None,

pandas/io/formats/info.py

+73-48
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
)
5454

5555

56+
show_counts_sub = dedent(
57+
"""\
58+
show_counts : bool, optional
59+
Whether to show the non-null counts."""
60+
)
61+
62+
5663
frame_examples_sub = dedent(
5764
"""\
5865
>>> int_values = [1, 2, 3, 4, 5]
@@ -147,6 +154,69 @@
147154
)
148155

149156

157+
frame_sub_kwargs = dict(
158+
klass="DataFrame",
159+
type_sub=" and columns",
160+
max_cols_sub=frame_max_cols_sub,
161+
null_counts_sub=frame_null_counts_sub,
162+
show_counts_sub=show_counts_sub,
163+
examples_sub=frame_examples_sub,
164+
see_also_sub=frame_see_also_sub,
165+
version_added_sub="",
166+
)
167+
168+
169+
INFO_DOCSTRING = dedent(
170+
"""\
171+
Print a concise summary of a {klass}.
172+
173+
This method prints information about a {klass} including
174+
the index dtype{type_sub}, non-null values and memory usage.
175+
{version_added_sub}\
176+
177+
Parameters
178+
----------
179+
data : {klass}
180+
{klass} to print information about.
181+
verbose : bool, optional
182+
Whether to print the full summary. By default, the setting in
183+
``pandas.options.display.max_info_columns`` is followed.
184+
buf : writable buffer, defaults to sys.stdout
185+
Where to send the output. By default, the output is printed to
186+
sys.stdout. Pass a writable buffer if you need to further process
187+
the output.
188+
{max_cols_sub}
189+
memory_usage : bool, str, optional
190+
Specifies whether total memory usage of the {klass}
191+
elements (including the index) should be displayed. By default,
192+
this follows the ``pandas.options.display.memory_usage`` setting.
193+
194+
True always show memory usage. False never shows memory usage.
195+
A value of 'deep' is equivalent to "True with deep introspection".
196+
Memory usage is shown in human-readable units (base-2
197+
representation). Without deep introspection a memory estimation is
198+
made based in column dtype and number of rows assuming values
199+
consume the same memory amount for corresponding dtypes. With deep
200+
memory introspection, a real memory usage calculation is performed
201+
at the cost of computational resources.
202+
{show_counts_sub}s
203+
204+
Returns
205+
-------
206+
None
207+
This method prints a summary of a {klass} and returns None.
208+
209+
See Also
210+
--------
211+
{see_also_sub}
212+
213+
Examples
214+
--------
215+
{examples_sub}
216+
"""
217+
)
218+
219+
150220
def _put_str(s: str | Dtype, space: int) -> str:
151221
"""
152222
Make string of specified length, padding to the right if necessary.
@@ -293,53 +363,7 @@ def render(
293363
verbose: bool | None,
294364
show_counts: bool | None,
295365
) -> None:
296-
"""
297-
Print a concise summary of a {klass}.
298-
299-
This method prints information about a {klass} including
300-
the index dtype{type_sub}, non-null values and memory usage.
301-
{version_added_sub}\
302-
303-
Parameters
304-
----------
305-
data : {klass}
306-
{klass} to print information about.
307-
verbose : bool, optional
308-
Whether to print the full summary. By default, the setting in
309-
``pandas.options.display.max_info_columns`` is followed.
310-
buf : writable buffer, defaults to sys.stdout
311-
Where to send the output. By default, the output is printed to
312-
sys.stdout. Pass a writable buffer if you need to further process
313-
the output.
314-
{max_cols_sub}
315-
memory_usage : bool, str, optional
316-
Specifies whether total memory usage of the {klass}
317-
elements (including the index) should be displayed. By default,
318-
this follows the ``pandas.options.display.memory_usage`` setting.
319-
320-
True always show memory usage. False never shows memory usage.
321-
A value of 'deep' is equivalent to "True with deep introspection".
322-
Memory usage is shown in human-readable units (base-2
323-
representation). Without deep introspection a memory estimation is
324-
made based in column dtype and number of rows assuming values
325-
consume the same memory amount for corresponding dtypes. With deep
326-
memory introspection, a real memory usage calculation is performed
327-
at the cost of computational resources.
328-
%(show_counts_sub)s
329-
330-
Returns
331-
-------
332-
None
333-
This method prints a summary of a {klass} and returns None.
334-
335-
See Also
336-
--------
337-
{see_also_sub}
338-
339-
Examples
340-
--------
341-
{examples_sub}
342-
"""
366+
pass
343367

344368

345369
class DataFrameInfo(BaseInfo):
@@ -402,11 +426,12 @@ def memory_usage_bytes(self) -> int:
402426
return self.data.memory_usage(index=True, deep=deep).sum()
403427

404428
@doc(
405-
BaseInfo.render,
429+
INFO_DOCSTRING,
406430
klass="DataFrame",
407431
type_sub=" and columns",
408432
max_cols_sub=frame_max_cols_sub,
409433
null_counts_sub=frame_null_counts_sub,
434+
show_counts_sub=show_counts_sub,
410435
examples_sub=frame_examples_sub,
411436
see_also_sub=frame_see_also_sub,
412437
version_added_sub="",

0 commit comments

Comments
 (0)