From 25b50b3fa6ff81c51da61c346cef4d455dad7c3c Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Wed, 11 Dec 2013 22:12:40 -0500 Subject: [PATCH 1/2] DISP: show column dtype in DataFrame.info() output --- pandas/core/frame.py | 4 +++- pandas/tests/test_frame.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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 From 85146885f18dd25f116a13025a663470399faa97 Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Sat, 14 Dec 2013 13:04:48 -0500 Subject: [PATCH 2/2] TST: add test for lack of Series.info --- pandas/tests/test_series.py | 6 ++++++ 1 file changed, 6 insertions(+) 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):