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 5 commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ Deprecations
- The ``how`` keyword in :meth:`PeriodIndex.astype` is deprecated and will be removed in a future version, use ``index.to_timestamp(how=how)`` instead (:issue:`37982`)
- Deprecated :meth:`Index.asi8` for :class:`Index` subclasses other than :class:`DatetimeIndex`, :class:`TimedeltaIndex`, and :class:`PeriodIndex` (:issue:`37877`)
- The ``inplace`` parameter of :meth:`Categorical.remove_unused_categories` is deprecated and will be removed in a future version (:issue:`37643`)
- The ``null_counts`` parameter of :meth:`DataFrame.info` is deprecated and will be removed in a future version (:issue:`37999`)
Copy link
Member

Choose a reason for hiding this comment

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

Can you indicate here that the keyword is renamed to show_counts ?

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's an unrelated test on Travis that fails intermittently

FAILED pandas/tests/plotting/frame/test_frame.py::TestDataFramePlots::test_area_lim


.. ---------------------------------------------------------------------------

Expand Down
21 changes: 17 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2531,14 +2531,17 @@ def to_html(
is used. By default, the setting in
``pandas.options.display.max_info_columns`` is used."""
),
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."""
shows the counts, and False never shows the counts.
null_counts : bool, optional
.. deprecated:: 1.2.0
Use show_counts instead."""
),
examples_sub=dedent(
"""\
Expand Down Expand Up @@ -2639,8 +2642,18 @@ 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:
if show_counts is not None:
raise ValueError("null_counts used with show_counts")
Copy link
Member

Choose a reason for hiding this comment

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

I suggest adding Use show_counts.
Otherwise looks good to me.

warnings.warn(
"null_counts is deprecated. Use show_counts instead",
FutureWarning,
stacklevel=2,
)
show_counts = null_counts
info = DataFrameInfo(
data=self,
memory_usage=memory_usage,
Expand All @@ -2649,7 +2662,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
2 changes: 1 addition & 1 deletion pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ 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
%(show_counts_sub)s

Returns
-------
Expand Down
16 changes: 14 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 All @@ -194,6 +194,18 @@ def check(null_counts, result):
check(True, False)
check(False, False)

# GH37999
with tm.assert_produces_warning(
FutureWarning, match="null_counts is deprecated.+"
):
buf = StringIO()
df.info(buf=buf, null_counts=True)
assert "non-null" in buf.getvalue()

# GH37999
with pytest.raises(ValueError, match="null_counts used with show_counts"):
df.info(null_counts=True, show_counts=True)

def test_repr_truncation(self):
max_len = 20
with option_context("display.max_colwidth", max_len):
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