diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 90641a833f2a7..4aad541e3fcd1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1426,10 +1426,12 @@ def info(self, verbose=True, buf=None, max_cols=None): if len(cols) != len(counts): # pragma: no cover raise AssertionError('Columns must equal counts (%d != %d)' % (len(cols), len(counts))) + dtypes = self.dtypes for col, count in compat.iteritems(counts): + dtype = dtypes[col] col = com.pprint_thing(col) lines.append(_put_str(col, space) + - '%d non-null values' % count) + '%d non-null %s' % (count, dtype)) else: lines.append(self.columns.summary(name='Columns')) diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 5b501de026c57..8103812a633df 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -6018,6 +6018,21 @@ def test_info_duplicate_columns(self): columns=['a', 'a', 'b', 'b']) frame.info(buf=io) + def test_info_shows_column_dtypes(self): + dtypes = ['int64', 'float64', 'datetime64[ns]', 'timedelta64[ns]', + 'complex128', 'object', 'bool'] + data = {} + n = 10 + for i, dtype in enumerate(dtypes): + data[i] = np.random.randint(2, size=n).astype(dtype) + df = DataFrame(data) + buf = StringIO() + df.info(buf=buf) + res = buf.getvalue() + for i, dtype in enumerate(dtypes): + name = '%d %d non-null %s' % (i, n, dtype) + assert name in res + def test_dtypes(self): self.mixed_frame['bool'] = self.mixed_frame['A'] > 0 result = self.mixed_frame.dtypes diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index d3104cdfad062..3e0a719bd93bd 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -2741,6 +2741,12 @@ def test_fillna_raise(self): self.assertRaises(TypeError, s.fillna, [1, 2]) self.assertRaises(TypeError, s.fillna, (1, 2)) + def test_raise_on_info(self): + s = Series(np.random.randn(10)) + with tm.assertRaises(AttributeError): + s.info() + + # TimeSeries-specific def test_fillna(self):