Skip to content

Commit

Permalink
Groupby Whitelist Cleanup (pandas-dev#23972)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd authored and Pingviinituutti committed Feb 28, 2019
1 parent fc4c580 commit b40f4a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 67 deletions.
27 changes: 7 additions & 20 deletions pandas/core/groupby/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,22 @@ def _gotitem(self, key, ndim, subset=None):

# special case to prevent duplicate plots when catching exceptions when
# forwarding methods from NDFrames
plotting_methods = frozenset(['plot', 'boxplot', 'hist'])
plotting_methods = frozenset(['plot', 'hist'])

common_apply_whitelist = frozenset([
'last', 'first',
'head', 'tail', 'median',
'mean', 'sum', 'min', 'max',
'cumcount', 'ngroup',
'resample',
'rank', 'quantile',
'fillna',
'mad',
'any', 'all',
'take',
'idxmax', 'idxmin',
'shift', 'tshift',
'ffill', 'bfill',
'pct_change', 'skew',
'corr', 'cov', 'diff',
'quantile', 'fillna', 'mad', 'take',
'idxmax', 'idxmin', 'tshift',
'skew', 'corr', 'cov', 'diff'
]) | plotting_methods

series_apply_whitelist = ((common_apply_whitelist |
{'nlargest', 'nsmallest',
'is_monotonic_increasing',
'is_monotonic_decreasing'}) -
{'boxplot'}) | frozenset(['dtype', 'unique'])
'is_monotonic_decreasing'})
) | frozenset(['dtype', 'unique'])

dataframe_apply_whitelist = ((common_apply_whitelist |
frozenset(['dtypes', 'corrwith'])) -
{'boxplot'})
frozenset(['dtypes', 'corrwith'])))

cython_transforms = frozenset(['cumprod', 'cumsum', 'shift',
'cummin', 'cummax'])
Expand Down
47 changes: 0 additions & 47 deletions pandas/tests/groupby/test_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,16 @@
AGG_FUNCTIONS_WITH_SKIPNA = ['skew', 'mad']

df_whitelist = [
'last',
'first',
'mean',
'sum',
'min',
'max',
'head',
'tail',
'cumcount',
'ngroup',
'resample',
'rank',
'quantile',
'fillna',
'mad',
'any',
'all',
'take',
'idxmax',
'idxmin',
'shift',
'tshift',
'ffill',
'bfill',
'pct_change',
'skew',
'plot',
'hist',
'median',
'dtypes',
'corrwith',
'corr',
Expand All @@ -57,35 +38,16 @@ def df_whitelist_fixture(request):


s_whitelist = [
'last',
'first',
'mean',
'sum',
'min',
'max',
'head',
'tail',
'cumcount',
'ngroup',
'resample',
'rank',
'quantile',
'fillna',
'mad',
'any',
'all',
'take',
'idxmax',
'idxmin',
'shift',
'tshift',
'ffill',
'bfill',
'pct_change',
'skew',
'plot',
'hist',
'median',
'dtype',
'corr',
'cov',
Expand Down Expand Up @@ -150,17 +112,8 @@ def test_groupby_whitelist(df_letters, whitelist):
def check_whitelist(obj, df, m):
# check the obj for a particular whitelist m

# these are aliases so ok to have the alias __name__
alias = {'bfill': 'backfill',
'ffill': 'pad',
'boxplot': None}

gb = obj.groupby(df.letters)

m = alias.get(m, m)
if m is None:
return

f = getattr(type(gb), m)

# name
Expand Down

0 comments on commit b40f4a2

Please sign in to comment.