Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ENH: get_dtype_counts publicized and added dtypes property

  • Loading branch information...
commit dca3c5c5a6a3769ee01465baca04cfdfa66a4f76 1 parent 9ae251b
Wes McKinney wesm authored
4 RELEASE.rst
View
@@ -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()
10 pandas/core/frame.py
View
@@ -648,11 +648,15 @@ 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:
@@ -660,7 +664,7 @@ def _get_dtype_counts(self):
else:
counts[series.dtype] = 1
- return counts
+ return Series(counts)
#----------------------------------------------------------------------
# properties for index and columns
6 pandas/tests/test_frame.py
View
@@ -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:]
Please sign in to comment.
Something went wrong with that request. Please try again.