Skip to content

Commit 08913f8

Browse files
authored
DOC: Deprecate null_counts parameter of DataFrame.info (#37999)
1 parent c6eb725 commit 08913f8

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ Deprecations
483483
- 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`)
484484
- Deprecated :meth:`Index.asi8` for :class:`Index` subclasses other than :class:`DatetimeIndex`, :class:`TimedeltaIndex`, and :class:`PeriodIndex` (:issue:`37877`)
485485
- The ``inplace`` parameter of :meth:`Categorical.remove_unused_categories` is deprecated and will be removed in a future version (:issue:`37643`)
486+
- The ``null_counts`` parameter of :meth:`DataFrame.info` is deprecated and replaced by ``show_counts``. It will be removed in a future version (:issue:`37999`)
486487

487488
.. ---------------------------------------------------------------------------
488489

pandas/core/frame.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -2532,14 +2532,17 @@ def to_html(
25322532
is used. By default, the setting in
25332533
``pandas.options.display.max_info_columns`` is used."""
25342534
),
2535-
null_counts_sub=dedent(
2535+
show_counts_sub=dedent(
25362536
"""\
2537-
null_counts : bool, optional
2537+
show_counts : bool, optional
25382538
Whether to show the non-null counts. By default, this is shown
25392539
only if the DataFrame is smaller than
25402540
``pandas.options.display.max_info_rows`` and
25412541
``pandas.options.display.max_info_columns``. A value of True always
2542-
shows the counts, and False never shows the counts."""
2542+
shows the counts, and False never shows the counts.
2543+
null_counts : bool, optional
2544+
.. deprecated:: 1.2.0
2545+
Use show_counts instead."""
25432546
),
25442547
examples_sub=dedent(
25452548
"""\
@@ -2640,8 +2643,18 @@ def info(
26402643
buf: Optional[IO[str]] = None,
26412644
max_cols: Optional[int] = None,
26422645
memory_usage: Optional[Union[bool, str]] = None,
2646+
show_counts: Optional[bool] = None,
26432647
null_counts: Optional[bool] = None,
26442648
) -> None:
2649+
if null_counts is not None:
2650+
if show_counts is not None:
2651+
raise ValueError("null_counts used with show_counts. Use show_counts.")
2652+
warnings.warn(
2653+
"null_counts is deprecated. Use show_counts instead",
2654+
FutureWarning,
2655+
stacklevel=2,
2656+
)
2657+
show_counts = null_counts
26452658
info = DataFrameInfo(
26462659
data=self,
26472660
memory_usage=memory_usage,
@@ -2650,7 +2663,7 @@ def info(
26502663
buf=buf,
26512664
max_cols=max_cols,
26522665
verbose=verbose,
2653-
show_counts=null_counts,
2666+
show_counts=show_counts,
26542667
)
26552668

26562669
def memory_usage(self, index=True, deep=False) -> Series:

pandas/io/formats/info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def render(
203203
consume the same memory amount for corresponding dtypes. With deep
204204
memory introspection, a real memory usage calculation is performed
205205
at the cost of computational resources.
206-
%(null_counts_sub)s
206+
%(show_counts_sub)s
207207
208208
Returns
209209
-------

pandas/tests/io/formats/test_format.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ def test_show_null_counts(self):
177177
df = DataFrame(1, columns=range(10), index=range(10))
178178
df.iloc[1, 1] = np.nan
179179

180-
def check(null_counts, result):
180+
def check(show_counts, result):
181181
buf = StringIO()
182-
df.info(buf=buf, null_counts=null_counts)
182+
df.info(buf=buf, show_counts=show_counts)
183183
assert ("non-null" in buf.getvalue()) is result
184184

185185
with option_context(
@@ -194,6 +194,18 @@ def check(null_counts, result):
194194
check(True, False)
195195
check(False, False)
196196

197+
# GH37999
198+
with tm.assert_produces_warning(
199+
FutureWarning, match="null_counts is deprecated.+"
200+
):
201+
buf = StringIO()
202+
df.info(buf=buf, null_counts=True)
203+
assert "non-null" in buf.getvalue()
204+
205+
# GH37999
206+
with pytest.raises(ValueError, match=r"null_counts used with show_counts.+"):
207+
df.info(null_counts=True, show_counts=True)
208+
197209
def test_repr_truncation(self):
198210
max_len = 20
199211
with option_context("display.max_colwidth", max_len):

pandas/tests/io/formats/test_info.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_info_verbose_with_counts_spacing(
161161
"""Test header column, spacer, first line and last line in verbose mode."""
162162
frame = DataFrame(np.random.randn(3, size))
163163
buf = StringIO()
164-
frame.info(verbose=True, null_counts=True, buf=buf)
164+
frame.info(verbose=True, show_counts=True, buf=buf)
165165
all_lines = buf.getvalue().splitlines()
166166
# Here table would contain only header, separator and table lines
167167
# dframe repr, index summary, memory usage and dtypes are excluded
@@ -480,7 +480,7 @@ def test_info_int_columns():
480480
# GH#37245
481481
df = DataFrame({1: [1, 2], 2: [2, 3]}, index=["A", "B"])
482482
buf = StringIO()
483-
df.info(null_counts=True, buf=buf)
483+
df.info(show_counts=True, buf=buf)
484484
result = buf.getvalue()
485485
expected = textwrap.dedent(
486486
"""\

0 commit comments

Comments
 (0)