Skip to content

Commit 7c13220

Browse files
author
Pratap Vardhan
committed
TST: df.info(null_counts=False) header as Dtype
1 parent ff70d33 commit 7c13220

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

doc/source/whatsnew/v0.24.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Current Behavior:
7171
Output Formatting Enhancements
7272
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7373

74-
- `df.info()` now shows line numbers for the columns summary (:issue:`17304`)
74+
- :func:`DataFrame.info` now shows line numbers for the columns summary (:issue:`17304`)
7575

7676
.. ipython:: python
7777

pandas/core/frame.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,8 +2121,8 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None,
21212121
<class 'pandas.core.frame.DataFrame'>
21222122
RangeIndex: 5 entries, 0 to 4
21232123
Data columns (total 3 columns):
2124-
#. Column Non-Null Count
2125-
--- ------ --------------
2124+
#. Column Non-Null Count & Dtype
2125+
--- ------ ----------------------
21262126
0 int_col 5 non-null int64
21272127
1 text_col 5 non-null object
21282128
2 float_col 5 non-null float64
@@ -2163,8 +2163,8 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None,
21632163
<class 'pandas.core.frame.DataFrame'>
21642164
RangeIndex: 1000000 entries, 0 to 999999
21652165
Data columns (total 3 columns):
2166-
#. Column Non-Null Count
2167-
--- ------ --------------
2166+
#. Column Non-Null Count & Dtype
2167+
--- ------ ----------------------
21682168
0 column_1 1000000 non-null object
21692169
1 column_2 1000000 non-null object
21702170
2 column_3 1000000 non-null object
@@ -2175,8 +2175,8 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None,
21752175
<class 'pandas.core.frame.DataFrame'>
21762176
RangeIndex: 1000000 entries, 0 to 999999
21772177
Data columns (total 3 columns):
2178-
#. Column Non-Null Count
2179-
--- ------ --------------
2178+
#. Column Non-Null Count & Dtype
2179+
--- ------ ----------------------
21802180
0 column_1 1000000 non-null object
21812181
1 column_2 1000000 non-null object
21822182
2 column_3 1000000 non-null object
@@ -2232,10 +2232,10 @@ def _verbose_repr():
22322232
'Columns must equal counts '
22332233
'({cols_count} != {count})'.format(
22342234
cols_count=cols_count, count=len(counts)))
2235-
col_header = 'Non-Null Count'
2235+
col_header = 'Non-Null Count & Dtype'
22362236
tmpl = '{count} non-null {dtype}'
22372237
else:
2238-
col_header = 'dtype'
2238+
col_header = 'Dtype'
22392239
tmpl = '{count}{dtype}'
22402240
header += col_header
22412241

pandas/tests/frame/test_repr_info.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,33 @@ def test_info_memory(self):
217217
<class 'pandas.core.frame.DataFrame'>
218218
RangeIndex: 2 entries, 0 to 1
219219
Data columns (total 1 columns):
220-
#. Column Non-Null Count
221-
--- ------ --------------
220+
#. Column Non-Null Count & Dtype
221+
--- ------ ----------------------
222222
0 a 2 non-null int64
223223
dtypes: int64(1)
224224
memory usage: {} bytes
225225
""".format(bytes))
226226

227227
assert result == expected
228228

229+
def test_info_without_null_counts(self):
230+
df = pd.DataFrame({'a': [1, 2]})
231+
buf = StringIO()
232+
df.info(buf=buf, null_counts=False)
233+
buf.seek(0)
234+
lines = buf.readlines()
235+
result = ''.join(lines[:-1])
236+
expected = textwrap.dedent('''\
237+
<class 'pandas.core.frame.DataFrame'>
238+
RangeIndex: 2 entries, 0 to 1
239+
Data columns (total 1 columns):
240+
#. Column Dtype
241+
--- ------ -----
242+
0 a int64
243+
dtypes: int64(1)
244+
''')
245+
assert result == expected
246+
229247
def test_info_wide(self):
230248
from pandas import set_option, reset_option
231249
io = StringIO()

0 commit comments

Comments
 (0)