Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groupby Whitelist Cleanup #23972

Merged
merged 6 commits into from
Dec 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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