Skip to content
Permalink
Browse files

ENH: get_dtype_counts publicized and added dtypes property

  • Loading branch information...
wesm committed Sep 22, 2011
1 parent 9ae251b commit dca3c5c5a6a3769ee01465baca04cfdfa66a4f76
Showing with 17 additions and 3 deletions.
  1. +4 −0 RELEASE.rst
  2. +7 −3 pandas/core/frame.py
  3. +6 −0 pandas/tests/test_frame.py
@@ -13,6 +13,10 @@ pandas 0.4.1

This is a bug fix release

**New features / modules**

- Added new `DataFrame` methods `get_dtype_counts` and property `dtypes`

**Bug fixes**

- Fixed DataFrame constructor bug causing downstream problems (e.g. .copy()
@@ -648,19 +648,23 @@ def info(self, verbose=True, buf=None):
% (_stringify(cols[0]),
_stringify(cols[-1])))

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

def _get_dtype_counts(self):
@property
def dtypes(self):
return self.apply(lambda x: x.dtype)

def get_dtype_counts(self):
counts = {}
for _, series in self.iteritems():
if series.dtype in counts:
counts[series.dtype] += 1
else:
counts[series.dtype] = 1

return counts
return Series(counts)

#----------------------------------------------------------------------
# properties for index and columns
@@ -1543,6 +1543,12 @@ def test_info(self):
self.frame.info(buf=io)
self.tsframe.info(buf=io)

def test_dtypes(self):
self.mixed_frame['bool'] = self.mixed_frame['A'] > 0
result = self.mixed_frame.dtypes
expected = self.mixed_frame.dtypes
assert_series_equal(result, expected)

def test_append(self):
begin_index = self.frame.index[:5]
end_index = self.frame.index[5:]

0 comments on commit dca3c5c

Please sign in to comment.
You can’t perform that action at this time.