diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index f14ed08a27fae..230be08b4d8be 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -168,10 +168,10 @@ _series_apply_whitelist = ((_common_apply_whitelist | {'nlargest', 'nsmallest'}) - - {'boxplot'}) | frozenset(['dtype', 'unique']) + {'boxplot'}) | frozenset(['unique']) _dataframe_apply_whitelist = ((_common_apply_whitelist | - frozenset(['dtypes', 'corrwith'])) - + frozenset(['corrwith'])) - {'boxplot'}) _cython_transforms = frozenset(['cumprod', 'cumsum', 'shift', @@ -2782,13 +2782,6 @@ def _whitelist_method_generator(klass, whitelist): \""" f = %(self)s.__getattr__('%(name)s') return f(%(args)s)""" - property_wrapper_template = \ - """@property -def %(name)s(self) : - \""" - %(doc)s - \""" - return self.__getattr__('%(name)s')""" for name in whitelist: # don't override anything that was explicitly defined # in the base class @@ -2811,8 +2804,8 @@ def %(name)s(self) : 'self': args[0], 'args': ','.join(args_by_name)} else: - wrapper_template = property_wrapper_template - params = {'name': name, 'doc': doc} + msg = 'property %s should be implemented directly.' % name + raise ValueError(msg, type(f)) yield wrapper_template % params @@ -2824,6 +2817,14 @@ class SeriesGroupBy(GroupBy): _series_apply_whitelist): exec(_def_str) + @property + def dtype(self): + """ + return the dtype object of the underlying data + """ + self._set_group_selection() + return self.apply(lambda x: x.dtype) + @property def _selection_name(self): """ @@ -3980,6 +3981,16 @@ class DataFrameGroupBy(NDFrameGroupBy): _block_agg_axis = 1 + @property + def dtypes(self): + """ + Return the dtypes in this object. + """ + # need to setup the selection + # as are not passed directly but in the grouper + self._set_group_selection() + return self.apply(lambda x: x.dtypes) + _agg_doc = dedent(""" Examples -------- diff --git a/pandas/tests/groupby/test_whitelist.py b/pandas/tests/groupby/test_whitelist.py index 1c5161d2ffb43..90eb3af3fa9bc 100644 --- a/pandas/tests/groupby/test_whitelist.py +++ b/pandas/tests/groupby/test_whitelist.py @@ -44,7 +44,6 @@ 'plot', 'hist', 'median', - 'dtypes', 'corrwith', 'corr', 'cov', @@ -81,7 +80,6 @@ 'plot', 'hist', 'median', - 'dtype', 'corr', 'cov', 'diff',