From 5151e33d0e9fa8f989c7a90341038b835957cb8c Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Wed, 25 Nov 2020 19:07:15 +0700 Subject: [PATCH 1/7] DOC: move info docs to DataFrameInfo --- pandas/core/frame.py | 116 +--------------------------- pandas/io/formats/info.py | 156 +++++++++++++++++++++++++++++++++++--- 2 files changed, 146 insertions(+), 126 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 5b87c4ea8b9cc..c70b0dc43821a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -159,7 +159,7 @@ from pandas.io.common import get_handle from pandas.io.formats import console, format as fmt -from pandas.io.formats.info import BaseInfo, DataFrameInfo +from pandas.io.formats.info import DataFrameInfo import pandas.plotting if TYPE_CHECKING: @@ -2520,119 +2520,7 @@ def to_html( ) # ---------------------------------------------------------------------- - @Substitution( - klass="DataFrame", - type_sub=" and columns", - max_cols_sub=dedent( - """\ - max_cols : int, optional - When to switch from the verbose to the truncated output. If the - DataFrame has more than `max_cols` columns, the truncated output - is used. By default, the setting in - ``pandas.options.display.max_info_columns`` is used.""" - ), - null_counts_sub=dedent( - """\ - null_counts : bool, optional - Whether to show the non-null counts. By default, this is shown - only if the DataFrame is smaller than - ``pandas.options.display.max_info_rows`` and - ``pandas.options.display.max_info_columns``. A value of True always - shows the counts, and False never shows the counts.""" - ), - examples_sub=dedent( - """\ - >>> int_values = [1, 2, 3, 4, 5] - >>> text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon'] - >>> float_values = [0.0, 0.25, 0.5, 0.75, 1.0] - >>> df = pd.DataFrame({"int_col": int_values, "text_col": text_values, - ... "float_col": float_values}) - >>> df - int_col text_col float_col - 0 1 alpha 0.00 - 1 2 beta 0.25 - 2 3 gamma 0.50 - 3 4 delta 0.75 - 4 5 epsilon 1.00 - - Prints information of all columns: - - >>> df.info(verbose=True) - - RangeIndex: 5 entries, 0 to 4 - Data columns (total 3 columns): - # Column Non-Null Count Dtype - --- ------ -------------- ----- - 0 int_col 5 non-null int64 - 1 text_col 5 non-null object - 2 float_col 5 non-null float64 - dtypes: float64(1), int64(1), object(1) - memory usage: 248.0+ bytes - - Prints a summary of columns count and its dtypes but not per column - information: - - >>> df.info(verbose=False) - - RangeIndex: 5 entries, 0 to 4 - Columns: 3 entries, int_col to float_col - dtypes: float64(1), int64(1), object(1) - memory usage: 248.0+ bytes - - Pipe output of DataFrame.info to buffer instead of sys.stdout, get - buffer content and writes to a text file: - - >>> import io - >>> buffer = io.StringIO() - >>> df.info(buf=buffer) - >>> s = buffer.getvalue() - >>> with open("df_info.txt", "w", - ... encoding="utf-8") as f: # doctest: +SKIP - ... f.write(s) - 260 - - The `memory_usage` parameter allows deep introspection mode, specially - useful for big DataFrames and fine-tune memory optimization: - - >>> random_strings_array = np.random.choice(['a', 'b', 'c'], 10 ** 6) - >>> df = pd.DataFrame({ - ... 'column_1': np.random.choice(['a', 'b', 'c'], 10 ** 6), - ... 'column_2': np.random.choice(['a', 'b', 'c'], 10 ** 6), - ... 'column_3': np.random.choice(['a', 'b', 'c'], 10 ** 6) - ... }) - >>> df.info() - - RangeIndex: 1000000 entries, 0 to 999999 - Data columns (total 3 columns): - # Column Non-Null Count Dtype - --- ------ -------------- ----- - 0 column_1 1000000 non-null object - 1 column_2 1000000 non-null object - 2 column_3 1000000 non-null object - dtypes: object(3) - memory usage: 22.9+ MB - - >>> df.info(memory_usage='deep') - - RangeIndex: 1000000 entries, 0 to 999999 - Data columns (total 3 columns): - # Column Non-Null Count Dtype - --- ------ -------------- ----- - 0 column_1 1000000 non-null object - 1 column_2 1000000 non-null object - 2 column_3 1000000 non-null object - dtypes: object(3) - memory usage: 165.9 MB""" - ), - see_also_sub=dedent( - """\ - DataFrame.describe: Generate descriptive statistics of DataFrame - columns. - DataFrame.memory_usage: Memory usage of DataFrame columns.""" - ), - version_added_sub="", - ) - @doc(BaseInfo.render) + @doc(DataFrameInfo.render) def info( self, verbose: Optional[bool] = None, diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 563dbaa06e526..268d423b0046a 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -1,5 +1,6 @@ from abc import ABC, abstractmethod import sys +from textwrap import dedent from typing import ( IO, TYPE_CHECKING, @@ -15,6 +16,7 @@ from pandas._config import get_option from pandas._typing import Dtype, FrameOrSeriesUnion +from pandas.util._decorators import doc from pandas.core.indexes.api import Index @@ -25,6 +27,132 @@ from pandas.core.frame import DataFrame +frame_max_cols_sub = dedent( + """\ + max_cols : int, optional + When to switch from the verbose to the truncated output. If the + DataFrame has more than `max_cols` columns, the truncated output + is used. By default, the setting in + ``pandas.options.display.max_info_columns`` is used.""" +) + + +frame_null_counts_sub = dedent( + """\ + null_counts : bool, optional + Whether to show the non-null counts. By default, this is shown + only if the DataFrame is smaller than + ``pandas.options.display.max_info_rows`` and + ``pandas.options.display.max_info_columns``. A value of True always + shows the counts, and False never shows the counts.""" +) + + +frame_examples_sub = dedent( + """\ + >>> int_values = [1, 2, 3, 4, 5] + >>> text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon'] + >>> float_values = [0.0, 0.25, 0.5, 0.75, 1.0] + >>> df = pd.DataFrame({"int_col": int_values, "text_col": text_values, + ... "float_col": float_values}) + >>> df + int_col text_col float_col + 0 1 alpha 0.00 + 1 2 beta 0.25 + 2 3 gamma 0.50 + 3 4 delta 0.75 + 4 5 epsilon 1.00 + + Prints information of all columns: + + >>> df.info(verbose=True) + + RangeIndex: 5 entries, 0 to 4 + Data columns (total 3 columns): + # Column Non-Null Count Dtype + --- ------ -------------- ----- + 0 int_col 5 non-null int64 + 1 text_col 5 non-null object + 2 float_col 5 non-null float64 + dtypes: float64(1), int64(1), object(1) + memory usage: 248.0+ bytes + + Prints a summary of columns count and its dtypes but not per column + information: + + >>> df.info(verbose=False) + + RangeIndex: 5 entries, 0 to 4 + Columns: 3 entries, int_col to float_col + dtypes: float64(1), int64(1), object(1) + memory usage: 248.0+ bytes + + Pipe output of DataFrame.info to buffer instead of sys.stdout, get + buffer content and writes to a text file: + + >>> import io + >>> buffer = io.StringIO() + >>> df.info(buf=buffer) + >>> s = buffer.getvalue() + >>> with open("df_info.txt", "w", + ... encoding="utf-8") as f: # doctest: +SKIP + ... f.write(s) + 260 + + The `memory_usage` parameter allows deep introspection mode, specially + useful for big DataFrames and fine-tune memory optimization: + + >>> random_strings_array = np.random.choice(['a', 'b', 'c'], 10 ** 6) + >>> df = pd.DataFrame({ + ... 'column_1': np.random.choice(['a', 'b', 'c'], 10 ** 6), + ... 'column_2': np.random.choice(['a', 'b', 'c'], 10 ** 6), + ... 'column_3': np.random.choice(['a', 'b', 'c'], 10 ** 6) + ... }) + >>> df.info() + + RangeIndex: 1000000 entries, 0 to 999999 + Data columns (total 3 columns): + # Column Non-Null Count Dtype + --- ------ -------------- ----- + 0 column_1 1000000 non-null object + 1 column_2 1000000 non-null object + 2 column_3 1000000 non-null object + dtypes: object(3) + memory usage: 22.9+ MB + + >>> df.info(memory_usage='deep') + + RangeIndex: 1000000 entries, 0 to 999999 + Data columns (total 3 columns): + # Column Non-Null Count Dtype + --- ------ -------------- ----- + 0 column_1 1000000 non-null object + 1 column_2 1000000 non-null object + 2 column_3 1000000 non-null object + dtypes: object(3) + memory usage: 165.9 MB""" +) + + +frame_see_also_sub = dedent( + """\ + DataFrame.describe: Generate descriptive statistics of DataFrame + columns. + DataFrame.memory_usage: Memory usage of DataFrame columns.""" +) + + +frame_subs = { + "klass": "DataFrame", + "type_sub": " and columns", + "max_cols_sub": frame_max_cols_sub, + "null_counts_sub": frame_null_counts_sub, + "examples_sub": frame_examples_sub, + "see_also_sub": frame_see_also_sub, + "version_added_sub": "", +} + + def _put_str(s: Union[str, Dtype], space: int) -> str: """ Make string of specified length, padding to the right if necessary. @@ -172,16 +300,16 @@ def render( show_counts: Optional[bool], ) -> None: """ - Print a concise summary of a %(klass)s. + Print a concise summary of a {klass}. - This method prints information about a %(klass)s including - the index dtype%(type_sub)s, non-null values and memory usage. - %(version_added_sub)s\ + This method prints information about a {klass} including + the index dtype{type_sub}, non-null values and memory usage. + {version_added_sub}\ Parameters ---------- - data : %(klass)s - %(klass)s to print information about. + data : {klass} + {klass} to print information about. verbose : bool, optional Whether to print the full summary. By default, the setting in ``pandas.options.display.max_info_columns`` is followed. @@ -189,9 +317,9 @@ def render( Where to send the output. By default, the output is printed to sys.stdout. Pass a writable buffer if you need to further process the output. - %(max_cols_sub)s + {max_cols_sub} memory_usage : bool, str, optional - Specifies whether total memory usage of the %(klass)s + Specifies whether total memory usage of the {klass} elements (including the index) should be displayed. By default, this follows the ``pandas.options.display.memory_usage`` setting. @@ -203,20 +331,20 @@ def render( consume the same memory amount for corresponding dtypes. With deep memory introspection, a real memory usage calculation is performed at the cost of computational resources. - %(null_counts_sub)s + {null_counts_sub} Returns ------- None - This method prints a summary of a %(klass)s and returns None. + This method prints a summary of a {klass} and returns None. See Also -------- - %(see_also_sub)s + {see_also_sub} Examples -------- - %(examples_sub)s + {examples_sub} """ @@ -279,6 +407,10 @@ def memory_usage_bytes(self) -> int: deep = False return self.data.memory_usage(index=True, deep=deep).sum() + @doc( + BaseInfo.render, + **frame_subs, + ) def render( self, *, From 751143ca12842b040db1a54bf375dbf6a3403951 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 3 Jun 2021 11:09:53 +0700 Subject: [PATCH 2/7] Drop variable frame_subs --- pandas/io/formats/info.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 09c26844756cc..6701c336a0ecf 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -147,17 +147,6 @@ ) -frame_subs = { - "klass": "DataFrame", - "type_sub": " and columns", - "max_cols_sub": frame_max_cols_sub, - "null_counts_sub": frame_null_counts_sub, - "examples_sub": frame_examples_sub, - "see_also_sub": frame_see_also_sub, - "version_added_sub": "", -} - - def _put_str(s: str | Dtype, space: int) -> str: """ Make string of specified length, padding to the right if necessary. @@ -414,7 +403,13 @@ def memory_usage_bytes(self) -> int: @doc( BaseInfo.render, - **frame_subs, + klass="DataFrame", + type_sub=" and columns", + max_cols_sub=frame_max_cols_sub, + null_counts_sub=frame_null_counts_sub, + examples_sub=frame_examples_sub, + see_also_sub=frame_see_also_sub, + version_added_sub="", ) def render( self, From 7e213349aa8c362835e785d6a7c8348ab6b85ebb Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 3 Jun 2021 17:16:42 +0700 Subject: [PATCH 3/7] Extract INFO_DOCSTRING to fix doc decorator --- pandas/core/frame.py | 7 ++- pandas/io/formats/info.py | 121 +++++++++++++++++++++++--------------- 2 files changed, 78 insertions(+), 50 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6df85e6360118..f8e3bbf802228 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -201,7 +201,10 @@ console, format as fmt, ) -from pandas.io.formats.info import DataFrameInfo +from pandas.io.formats.info import ( + DataFrameInfo, + frame_sub_kwargs, +) import pandas.plotting if TYPE_CHECKING: @@ -3000,7 +3003,7 @@ def to_xml( return xml_formatter.write_output() # ---------------------------------------------------------------------- - @doc(DataFrameInfo.render) + @doc(DataFrameInfo.render, **frame_sub_kwargs) def info( self, verbose: bool | None = None, diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 6701c336a0ecf..09cd9e92cc433 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -53,6 +53,13 @@ ) +show_counts_sub = dedent( + """\ + show_counts : bool, optional + Whether to show the non-null counts.""" +) + + frame_examples_sub = dedent( """\ >>> int_values = [1, 2, 3, 4, 5] @@ -147,6 +154,69 @@ ) +frame_sub_kwargs = { + "klass": "DataFrame", + "type_sub": " and columns", + "max_cols_sub": frame_max_cols_sub, + "null_counts_sub": frame_null_counts_sub, + "show_counts_sub": show_counts_sub, + "examples_sub": frame_examples_sub, + "see_also_sub": frame_see_also_sub, + "version_added_sub": "", +} + + +INFO_DOCSTRING = dedent( + """\ + Print a concise summary of a {klass}. + + This method prints information about a {klass} including + the index dtype{type_sub}, non-null values and memory usage. + {version_added_sub}\ + + Parameters + ---------- + data : {klass} + {klass} to print information about. + verbose : bool, optional + Whether to print the full summary. By default, the setting in + ``pandas.options.display.max_info_columns`` is followed. + buf : writable buffer, defaults to sys.stdout + Where to send the output. By default, the output is printed to + sys.stdout. Pass a writable buffer if you need to further process + the output. + {max_cols_sub} + memory_usage : bool, str, optional + Specifies whether total memory usage of the {klass} + elements (including the index) should be displayed. By default, + this follows the ``pandas.options.display.memory_usage`` setting. + + True always show memory usage. False never shows memory usage. + A value of 'deep' is equivalent to "True with deep introspection". + Memory usage is shown in human-readable units (base-2 + representation). Without deep introspection a memory estimation is + made based in column dtype and number of rows assuming values + consume the same memory amount for corresponding dtypes. With deep + memory introspection, a real memory usage calculation is performed + at the cost of computational resources. + {show_counts_sub}s + + Returns + ------- + None + This method prints a summary of a {klass} and returns None. + + See Also + -------- + {see_also_sub} + + Examples + -------- + {examples_sub} + """ +) + + def _put_str(s: str | Dtype, space: int) -> str: """ Make string of specified length, padding to the right if necessary. @@ -293,53 +363,7 @@ def render( verbose: bool | None, show_counts: bool | None, ) -> None: - """ - Print a concise summary of a {klass}. - - This method prints information about a {klass} including - the index dtype{type_sub}, non-null values and memory usage. - {version_added_sub}\ - - Parameters - ---------- - data : {klass} - {klass} to print information about. - verbose : bool, optional - Whether to print the full summary. By default, the setting in - ``pandas.options.display.max_info_columns`` is followed. - buf : writable buffer, defaults to sys.stdout - Where to send the output. By default, the output is printed to - sys.stdout. Pass a writable buffer if you need to further process - the output. - {max_cols_sub} - memory_usage : bool, str, optional - Specifies whether total memory usage of the {klass} - elements (including the index) should be displayed. By default, - this follows the ``pandas.options.display.memory_usage`` setting. - - True always show memory usage. False never shows memory usage. - A value of 'deep' is equivalent to "True with deep introspection". - Memory usage is shown in human-readable units (base-2 - representation). Without deep introspection a memory estimation is - made based in column dtype and number of rows assuming values - consume the same memory amount for corresponding dtypes. With deep - memory introspection, a real memory usage calculation is performed - at the cost of computational resources. - %(show_counts_sub)s - - Returns - ------- - None - This method prints a summary of a {klass} and returns None. - - See Also - -------- - {see_also_sub} - - Examples - -------- - {examples_sub} - """ + pass class DataFrameInfo(BaseInfo): @@ -402,11 +426,12 @@ def memory_usage_bytes(self) -> int: return self.data.memory_usage(index=True, deep=deep).sum() @doc( - BaseInfo.render, + INFO_DOCSTRING, klass="DataFrame", type_sub=" and columns", max_cols_sub=frame_max_cols_sub, null_counts_sub=frame_null_counts_sub, + show_counts_sub=show_counts_sub, examples_sub=frame_examples_sub, see_also_sub=frame_see_also_sub, version_added_sub="", From d3261980332cf0c51c130d83c1cb3f099f0f7bc2 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Wed, 23 Jun 2021 00:35:26 +0700 Subject: [PATCH 4/7] Move INFO_DOCSTRING back to BaseInfo and fix reference --- pandas/io/formats/info.py | 101 ++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 53 deletions(-) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 09cd9e92cc433..b1f76ab5f9e0c 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -166,57 +166,6 @@ } -INFO_DOCSTRING = dedent( - """\ - Print a concise summary of a {klass}. - - This method prints information about a {klass} including - the index dtype{type_sub}, non-null values and memory usage. - {version_added_sub}\ - - Parameters - ---------- - data : {klass} - {klass} to print information about. - verbose : bool, optional - Whether to print the full summary. By default, the setting in - ``pandas.options.display.max_info_columns`` is followed. - buf : writable buffer, defaults to sys.stdout - Where to send the output. By default, the output is printed to - sys.stdout. Pass a writable buffer if you need to further process - the output. - {max_cols_sub} - memory_usage : bool, str, optional - Specifies whether total memory usage of the {klass} - elements (including the index) should be displayed. By default, - this follows the ``pandas.options.display.memory_usage`` setting. - - True always show memory usage. False never shows memory usage. - A value of 'deep' is equivalent to "True with deep introspection". - Memory usage is shown in human-readable units (base-2 - representation). Without deep introspection a memory estimation is - made based in column dtype and number of rows assuming values - consume the same memory amount for corresponding dtypes. With deep - memory introspection, a real memory usage calculation is performed - at the cost of computational resources. - {show_counts_sub}s - - Returns - ------- - None - This method prints a summary of a {klass} and returns None. - - See Also - -------- - {see_also_sub} - - Examples - -------- - {examples_sub} - """ -) - - def _put_str(s: str | Dtype, space: int) -> str: """ Make string of specified length, padding to the right if necessary. @@ -363,7 +312,53 @@ def render( verbose: bool | None, show_counts: bool | None, ) -> None: - pass + """ + Print a concise summary of a {klass}. + + This method prints information about a {klass} including + the index dtype{type_sub}, non-null values and memory usage. + {version_added_sub}\ + + Parameters + ---------- + data : {klass} + {klass} to print information about. + verbose : bool, optional + Whether to print the full summary. By default, the setting in + ``pandas.options.display.max_info_columns`` is followed. + buf : writable buffer, defaults to sys.stdout + Where to send the output. By default, the output is printed to + sys.stdout. Pass a writable buffer if you need to further process + the output. + {max_cols_sub} + memory_usage : bool, str, optional + Specifies whether total memory usage of the {klass} + elements (including the index) should be displayed. By default, + this follows the ``pandas.options.display.memory_usage`` setting. + + True always show memory usage. False never shows memory usage. + A value of 'deep' is equivalent to "True with deep introspection". + Memory usage is shown in human-readable units (base-2 + representation). Without deep introspection a memory estimation is + made based in column dtype and number of rows assuming values + consume the same memory amount for corresponding dtypes. With deep + memory introspection, a real memory usage calculation is performed + at the cost of computational resources. + {show_counts_sub}s + + Returns + ------- + None + This method prints a summary of a {klass} and returns None. + + See Also + -------- + {see_also_sub} + + Examples + -------- + {examples_sub} + """ class DataFrameInfo(BaseInfo): @@ -426,7 +421,7 @@ def memory_usage_bytes(self) -> int: return self.data.memory_usage(index=True, deep=deep).sum() @doc( - INFO_DOCSTRING, + BaseInfo.render.__doc__, klass="DataFrame", type_sub=" and columns", max_cols_sub=frame_max_cols_sub, From 05efde0dcf790c1c94e1efbd50c473907c1e5a3c Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Wed, 23 Jun 2021 00:49:46 +0700 Subject: [PATCH 5/7] Revert "Move INFO_DOCSTRING back to BaseInfo and fix reference" This reverts commit d3261980332cf0c51c130d83c1cb3f099f0f7bc2. --- pandas/io/formats/info.py | 101 ++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index b1f76ab5f9e0c..09cd9e92cc433 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -166,6 +166,57 @@ } +INFO_DOCSTRING = dedent( + """\ + Print a concise summary of a {klass}. + + This method prints information about a {klass} including + the index dtype{type_sub}, non-null values and memory usage. + {version_added_sub}\ + + Parameters + ---------- + data : {klass} + {klass} to print information about. + verbose : bool, optional + Whether to print the full summary. By default, the setting in + ``pandas.options.display.max_info_columns`` is followed. + buf : writable buffer, defaults to sys.stdout + Where to send the output. By default, the output is printed to + sys.stdout. Pass a writable buffer if you need to further process + the output. + {max_cols_sub} + memory_usage : bool, str, optional + Specifies whether total memory usage of the {klass} + elements (including the index) should be displayed. By default, + this follows the ``pandas.options.display.memory_usage`` setting. + + True always show memory usage. False never shows memory usage. + A value of 'deep' is equivalent to "True with deep introspection". + Memory usage is shown in human-readable units (base-2 + representation). Without deep introspection a memory estimation is + made based in column dtype and number of rows assuming values + consume the same memory amount for corresponding dtypes. With deep + memory introspection, a real memory usage calculation is performed + at the cost of computational resources. + {show_counts_sub}s + + Returns + ------- + None + This method prints a summary of a {klass} and returns None. + + See Also + -------- + {see_also_sub} + + Examples + -------- + {examples_sub} + """ +) + + def _put_str(s: str | Dtype, space: int) -> str: """ Make string of specified length, padding to the right if necessary. @@ -312,53 +363,7 @@ def render( verbose: bool | None, show_counts: bool | None, ) -> None: - """ - Print a concise summary of a {klass}. - - This method prints information about a {klass} including - the index dtype{type_sub}, non-null values and memory usage. - {version_added_sub}\ - - Parameters - ---------- - data : {klass} - {klass} to print information about. - verbose : bool, optional - Whether to print the full summary. By default, the setting in - ``pandas.options.display.max_info_columns`` is followed. - buf : writable buffer, defaults to sys.stdout - Where to send the output. By default, the output is printed to - sys.stdout. Pass a writable buffer if you need to further process - the output. - {max_cols_sub} - memory_usage : bool, str, optional - Specifies whether total memory usage of the {klass} - elements (including the index) should be displayed. By default, - this follows the ``pandas.options.display.memory_usage`` setting. - - True always show memory usage. False never shows memory usage. - A value of 'deep' is equivalent to "True with deep introspection". - Memory usage is shown in human-readable units (base-2 - representation). Without deep introspection a memory estimation is - made based in column dtype and number of rows assuming values - consume the same memory amount for corresponding dtypes. With deep - memory introspection, a real memory usage calculation is performed - at the cost of computational resources. - {show_counts_sub}s - - Returns - ------- - None - This method prints a summary of a {klass} and returns None. - - See Also - -------- - {see_also_sub} - - Examples - -------- - {examples_sub} - """ + pass class DataFrameInfo(BaseInfo): @@ -421,7 +426,7 @@ def memory_usage_bytes(self) -> int: return self.data.memory_usage(index=True, deep=deep).sum() @doc( - BaseInfo.render.__doc__, + INFO_DOCSTRING, klass="DataFrame", type_sub=" and columns", max_cols_sub=frame_max_cols_sub, From a686a22fa5be9e3a843822657d10af21e6bbe10b Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Wed, 23 Jun 2021 00:56:54 +0700 Subject: [PATCH 6/7] Handle merge conflict missed: null_counts and show_counts --- pandas/io/formats/info.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 09cd9e92cc433..842c08753e305 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -42,21 +42,17 @@ ) -frame_null_counts_sub = dedent( +show_counts_sub = dedent( """\ - null_counts : bool, optional + show_counts : bool, optional Whether to show the non-null counts. By default, this is shown only if the DataFrame is smaller than ``pandas.options.display.max_info_rows`` and ``pandas.options.display.max_info_columns``. A value of True always - shows the counts, and False never shows the counts.""" -) - - -show_counts_sub = dedent( - """\ - show_counts : bool, optional - Whether to show the non-null counts.""" + shows the counts, and False never shows the counts. + null_counts : bool, optional + .. deprecated:: 1.2.0 + Use show_counts instead.""" ) @@ -158,7 +154,6 @@ "klass": "DataFrame", "type_sub": " and columns", "max_cols_sub": frame_max_cols_sub, - "null_counts_sub": frame_null_counts_sub, "show_counts_sub": show_counts_sub, "examples_sub": frame_examples_sub, "see_also_sub": frame_see_also_sub, @@ -199,7 +194,7 @@ consume the same memory amount for corresponding dtypes. With deep memory introspection, a real memory usage calculation is performed at the cost of computational resources. - {show_counts_sub}s + {show_counts_sub} Returns ------- @@ -430,7 +425,6 @@ def memory_usage_bytes(self) -> int: klass="DataFrame", type_sub=" and columns", max_cols_sub=frame_max_cols_sub, - null_counts_sub=frame_null_counts_sub, show_counts_sub=show_counts_sub, examples_sub=frame_examples_sub, see_also_sub=frame_see_also_sub, From 5814bc998f46bf00c881b4b8abc0a95065eda83b Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Mon, 29 Nov 2021 13:34:57 +0700 Subject: [PATCH 7/7] FIX: newline in docstring --- pandas/io/formats/info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/formats/info.py b/pandas/io/formats/info.py index 83ce69580235a..9340d020cd6ce 100644 --- a/pandas/io/formats/info.py +++ b/pandas/io/formats/info.py @@ -164,7 +164,7 @@ INFO_DOCSTRING = dedent( - """\ + """ Print a concise summary of a {klass}. This method prints information about a {klass} including