Skip to content

Commit dca3c5c

Browse files
committed
ENH: get_dtype_counts publicized and added dtypes property
1 parent 9ae251b commit dca3c5c

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

RELEASE.rst

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ pandas 0.4.1
1313

1414
This is a bug fix release
1515

16+
**New features / modules**
17+
18+
- Added new `DataFrame` methods `get_dtype_counts` and property `dtypes`
19+
1620
**Bug fixes**
1721

1822
- Fixed DataFrame constructor bug causing downstream problems (e.g. .copy()

pandas/core/frame.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -648,19 +648,23 @@ def info(self, verbose=True, buf=None):
648648
% (_stringify(cols[0]),
649649
_stringify(cols[-1])))
650650

651-
counts = self._get_dtype_counts()
651+
counts = self.get_dtype_counts()
652652
dtypes = ['%s(%d)' % k for k in sorted(counts.iteritems())]
653653
buf.write(u'dtypes: %s' % ', '.join(dtypes))
654654

655-
def _get_dtype_counts(self):
655+
@property
656+
def dtypes(self):
657+
return self.apply(lambda x: x.dtype)
658+
659+
def get_dtype_counts(self):
656660
counts = {}
657661
for _, series in self.iteritems():
658662
if series.dtype in counts:
659663
counts[series.dtype] += 1
660664
else:
661665
counts[series.dtype] = 1
662666

663-
return counts
667+
return Series(counts)
664668

665669
#----------------------------------------------------------------------
666670
# properties for index and columns

pandas/tests/test_frame.py

+6
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,12 @@ def test_info(self):
15431543
self.frame.info(buf=io)
15441544
self.tsframe.info(buf=io)
15451545

1546+
def test_dtypes(self):
1547+
self.mixed_frame['bool'] = self.mixed_frame['A'] > 0
1548+
result = self.mixed_frame.dtypes
1549+
expected = self.mixed_frame.dtypes
1550+
assert_series_equal(result, expected)
1551+
15461552
def test_append(self):
15471553
begin_index = self.frame.index[:5]
15481554
end_index = self.frame.index[5:]

0 commit comments

Comments
 (0)