Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Deprecate null_counts parameter of DataFrame.info #37999

Merged
merged 6 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2629,8 +2629,16 @@ def info(
buf: Optional[IO[str]] = None,
max_cols: Optional[int] = None,
memory_usage: Optional[Union[bool, str]] = None,
show_counts: Optional[bool] = None,
null_counts: Optional[bool] = None,
) -> None:
if null_counts is not None and show_counts is None:
warnings.warn(
"null_counts is deprecated. Use show_counts instead",
FutureWarning,
stacklevel=2,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user will not get this warning when setting both arguments at the same time.
For example, df.info(null_counts = True, show_counts=False).
This type of invocation is incorrect and should raise an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

show_counts = null_counts
info = DataFrameInfo(
data=self,
memory_usage=memory_usage,
Expand All @@ -2639,7 +2647,7 @@ def info(
buf=buf,
max_cols=max_cols,
verbose=verbose,
show_counts=null_counts,
show_counts=show_counts,
)

def memory_usage(self, index=True, deep=False) -> Series:
Expand Down
5 changes: 4 additions & 1 deletion pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,15 @@ def to_buffer(
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 : bool, optional
show_counts : bool, optional
Whether to show the non-null counts. By default, this is shown
only if the %(klass)s 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.
null_counts : bool, optional
.. deprecated:: 1.2.0
Use show_counts instead.

Returns
-------
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def test_show_null_counts(self):
df = DataFrame(1, columns=range(10), index=range(10))
df.iloc[1, 1] = np.nan

def check(null_counts, result):
def check(show_counts, result):
buf = StringIO()
df.info(buf=buf, null_counts=null_counts)
df.info(buf=buf, show_counts=show_counts)
assert ("non-null" in buf.getvalue()) is result

with option_context(
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/formats/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_info_verbose_with_counts_spacing(
"""Test header column, spacer, first line and last line in verbose mode."""
frame = DataFrame(np.random.randn(3, size))
buf = StringIO()
frame.info(verbose=True, null_counts=True, buf=buf)
frame.info(verbose=True, show_counts=True, buf=buf)
all_lines = buf.getvalue().splitlines()
# Here table would contain only header, separator and table lines
# dframe repr, index summary, memory usage and dtypes are excluded
Expand Down Expand Up @@ -480,7 +480,7 @@ def test_info_int_columns():
# GH#37245
df = DataFrame({1: [1, 2], 2: [2, 3]}, index=["A", "B"])
buf = StringIO()
df.info(null_counts=True, buf=buf)
df.info(show_counts=True, buf=buf)
result = buf.getvalue()
expected = textwrap.dedent(
"""\
Expand Down