Skip to content

DOC: Fix language style #34924

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

Merged
merged 1 commit into from
Jun 23, 2020
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
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from .pandas_vb_common import tm

method_blacklist = {
method_blocklist = {
"object": {
"median",
"prod",
Expand Down Expand Up @@ -403,7 +403,7 @@ class GroupByMethods:
]

def setup(self, dtype, method, application):
if method in method_blacklist.get(dtype, {}):
if method in method_blocklist.get(dtype, {}):
raise NotImplementedError # skip benchmark
ngroups = 1000
size = ngroups * 2
Expand Down
6 changes: 3 additions & 3 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,19 @@ fi
### CODE ###
if [[ -z "$CHECK" || "$CHECK" == "code" ]]; then

MSG='Check import. No warnings, and blacklist some optional dependencies' ; echo $MSG
MSG='Check import. No warnings, and blocklist some optional dependencies' ; echo $MSG
python -W error -c "
import sys
import pandas
blacklist = {'bs4', 'gcsfs', 'html5lib', 'http', 'ipython', 'jinja2', 'hypothesis',
blocklist = {'bs4', 'gcsfs', 'html5lib', 'http', 'ipython', 'jinja2', 'hypothesis',
'lxml', 'matplotlib', 'numexpr', 'openpyxl', 'py', 'pytest', 's3fs', 'scipy',
'tables', 'urllib.request', 'xlrd', 'xlsxwriter', 'xlwt'}
# GH#28227 for some of these check for top-level modules, while others are
# more specific (e.g. urllib.request)
import_mods = set(m.split('.')[0] for m in sys.modules) | set(sys.modules)
mods = blacklist & import_mods
mods = blocklist & import_mods
if mods:
sys.stderr.write('err: pandas should not import: {}\n'.format(', '.join(mods)))
sys.exit(len(mods))
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.14.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Enhancements

- Implemented ``sem`` (standard error of the mean) operation for ``Series``,
``DataFrame``, ``Panel``, and ``Groupby`` (:issue:`6897`)
- Add ``nlargest`` and ``nsmallest`` to the ``Series`` ``groupby`` whitelist,
- Add ``nlargest`` and ``nsmallest`` to the ``Series`` ``groupby`` allowlist,
which means you can now use these methods on a ``SeriesGroupBy`` object
(:issue:`7053`).
- All offsets ``apply``, ``rollforward`` and ``rollback`` can now handle ``np.datetime64``, previously results in ``ApplyTypeError`` (:issue:`7452`)
Expand Down
14 changes: 7 additions & 7 deletions pandas/core/groupby/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Provide basic components for groupby. These definitions
hold the whitelist of methods that are exposed on the
hold the allowlist of methods that are exposed on the
SeriesGroupBy and the DataFrameGroupBy objects.
"""
import collections
Expand Down Expand Up @@ -53,7 +53,7 @@ def _gotitem(self, key, ndim, subset=None):
# forwarding methods from NDFrames
plotting_methods = frozenset(["plot", "hist"])

common_apply_whitelist = (
common_apply_allowlist = (
frozenset(
[
"quantile",
Expand All @@ -72,9 +72,9 @@ def _gotitem(self, key, ndim, subset=None):
| plotting_methods
)

series_apply_whitelist = (
series_apply_allowlist = (
(
common_apply_whitelist
common_apply_allowlist
| {
"nlargest",
"nsmallest",
Expand All @@ -84,13 +84,13 @@ def _gotitem(self, key, ndim, subset=None):
)
) | frozenset(["dtype", "unique"])

dataframe_apply_whitelist = common_apply_whitelist | frozenset(["dtypes", "corrwith"])
dataframe_apply_allowlist = common_apply_allowlist | frozenset(["dtypes", "corrwith"])

# cythonized transformations or canned "agg+broadcast", which do not
# require postprocessing of the result by transform.
cythonized_kernels = frozenset(["cumprod", "cumsum", "shift", "cummin", "cummax"])

cython_cast_blacklist = frozenset(["rank", "count", "size", "idxmin", "idxmax"])
cython_cast_blocklist = frozenset(["rank", "count", "size", "idxmin", "idxmax"])

# List of aggregation/reduction functions.
# These map each group to a single numeric value
Expand Down Expand Up @@ -186,4 +186,4 @@ def _gotitem(self, key, ndim, subset=None):
# Valid values of `name` for `groupby.transform(name)`
# NOTE: do NOT edit this directly. New additions should be inserted
# into the appropriate list above.
transform_kernel_whitelist = reduction_kernels | transformation_kernels
transform_kernel_allowlist = reduction_kernels | transformation_kernels
20 changes: 10 additions & 10 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ def prop(self):
return property(prop)


def pin_whitelisted_properties(klass: Type[FrameOrSeries], whitelist: FrozenSet[str]):
def pin_allowlisted_properties(klass: Type[FrameOrSeries], allowlist: FrozenSet[str]):
"""
Create GroupBy member defs for DataFrame/Series names in a whitelist.
Create GroupBy member defs for DataFrame/Series names in a allowlist.
Parameters
----------
klass : DataFrame or Series class
class where members are defined.
whitelist : frozenset[str]
allowlist : frozenset[str]
Set of names of klass methods to be constructed
Returns
Expand All @@ -143,7 +143,7 @@ class decorator
"""

def pinner(cls):
for name in whitelist:
for name in allowlist:
if hasattr(cls, name):
# don't override anything that was explicitly defined
# in the base class
Expand All @@ -157,9 +157,9 @@ def pinner(cls):
return pinner


@pin_whitelisted_properties(Series, base.series_apply_whitelist)
@pin_allowlisted_properties(Series, base.series_apply_allowlist)
class SeriesGroupBy(GroupBy[Series]):
_apply_whitelist = base.series_apply_whitelist
_apply_allowlist = base.series_apply_allowlist

def _iterate_slices(self) -> Iterable[Series]:
yield self._selected_obj
Expand Down Expand Up @@ -473,7 +473,7 @@ def transform(self, func, *args, engine="cython", engine_kwargs=None, **kwargs):
func, *args, engine=engine, engine_kwargs=engine_kwargs, **kwargs
)

elif func not in base.transform_kernel_whitelist:
elif func not in base.transform_kernel_allowlist:
msg = f"'{func}' is not a valid function name for transform(name)"
raise ValueError(msg)
elif func in base.cythonized_kernels:
Expand Down Expand Up @@ -835,10 +835,10 @@ def pct_change(self, periods=1, fill_method="pad", limit=None, freq=None):
return (filled / shifted) - 1


@pin_whitelisted_properties(DataFrame, base.dataframe_apply_whitelist)
@pin_allowlisted_properties(DataFrame, base.dataframe_apply_allowlist)
class DataFrameGroupBy(GroupBy[DataFrame]):

_apply_whitelist = base.dataframe_apply_whitelist
_apply_allowlist = base.dataframe_apply_allowlist

_agg_examples_doc = dedent(
"""
Expand Down Expand Up @@ -1456,7 +1456,7 @@ def transform(self, func, *args, engine="cython", engine_kwargs=None, **kwargs):
func, *args, engine=engine, engine_kwargs=engine_kwargs, **kwargs
)

elif func not in base.transform_kernel_whitelist:
elif func not in base.transform_kernel_allowlist:
msg = f"'{func}' is not a valid function name for transform(name)"
raise ValueError(msg)
elif func in base.cythonized_kernels:
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def _group_selection_context(groupby):

class _GroupBy(PandasObject, SelectionMixin, Generic[FrameOrSeries]):
_group_selection = None
_apply_whitelist: FrozenSet[str] = frozenset()
_apply_allowlist: FrozenSet[str] = frozenset()

def __init__(
self,
Expand Down Expand Up @@ -689,7 +689,7 @@ def _set_result_index_ordered(self, result):
return result

def _dir_additions(self):
return self.obj._dir_additions() | self._apply_whitelist
return self.obj._dir_additions() | self._apply_allowlist

def __getattr__(self, attr: str):
if attr in self._internal_names_set:
Expand Down Expand Up @@ -729,7 +729,7 @@ def pipe(self, func, *args, **kwargs):
plot = property(GroupByPlot)

def _make_wrapper(self, name):
assert name in self._apply_whitelist
assert name in self._apply_allowlist

self._set_group_selection()

Expand Down Expand Up @@ -944,7 +944,7 @@ def _transform_should_cast(self, func_nm: str) -> bool:
"""
filled_series = self.grouper.size().fillna(0)
assert filled_series is not None
return filled_series.gt(0).any() and func_nm not in base.cython_cast_blacklist
return filled_series.gt(0).any() and func_nm not in base.cython_cast_blocklist

def _cython_transform(self, how: str, numeric_only: bool = True, **kwargs):
output: Dict[base.OutputKey, np.ndarray] = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
]
AGG_FUNCTIONS_WITH_SKIPNA = ["skew", "mad"]

df_whitelist = [
df_allowlist = [
"quantile",
"fillna",
"mad",
Expand All @@ -50,12 +50,12 @@
]


@pytest.fixture(params=df_whitelist)
def df_whitelist_fixture(request):
@pytest.fixture(params=df_allowlist)
def df_allowlist_fixture(request):
return request.param


s_whitelist = [
s_allowlist = [
"quantile",
"fillna",
"mad",
Expand All @@ -78,8 +78,8 @@ def df_whitelist_fixture(request):
]


@pytest.fixture(params=s_whitelist)
def s_whitelist_fixture(request):
@pytest.fixture(params=s_allowlist)
def s_allowlist_fixture(request):
return request.param


Expand Down Expand Up @@ -119,22 +119,22 @@ def df_letters():
return df


@pytest.mark.parametrize("whitelist", [df_whitelist, s_whitelist])
def test_groupby_whitelist(df_letters, whitelist):
@pytest.mark.parametrize("allowlist", [df_allowlist, s_allowlist])
def test_groupby_allowlist(df_letters, allowlist):
df = df_letters
if whitelist == df_whitelist:
if allowlist == df_allowlist:
# dataframe
obj = df_letters
else:
obj = df_letters["floats"]

gb = obj.groupby(df.letters)

assert set(whitelist) == set(gb._apply_whitelist)
assert set(allowlist) == set(gb._apply_allowlist)


def check_whitelist(obj, df, m):
# check the obj for a particular whitelist m
def check_allowlist(obj, df, m):
# check the obj for a particular allowlist m

gb = obj.groupby(df.letters)

Expand All @@ -155,16 +155,16 @@ def check_whitelist(obj, df, m):
assert n.endswith(m)


def test_groupby_series_whitelist(df_letters, s_whitelist_fixture):
m = s_whitelist_fixture
def test_groupby_series_allowlist(df_letters, s_allowlist_fixture):
m = s_allowlist_fixture
df = df_letters
check_whitelist(df.letters, df, m)
check_allowlist(df.letters, df, m)


def test_groupby_frame_whitelist(df_letters, df_whitelist_fixture):
m = df_whitelist_fixture
def test_groupby_frame_allowlist(df_letters, df_allowlist_fixture):
m = df_allowlist_fixture
df = df_letters
check_whitelist(df, df, m)
check_allowlist(df, df, m)


@pytest.fixture
Expand All @@ -187,10 +187,10 @@ def raw_frame():
@pytest.mark.parametrize("axis", [0, 1])
@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("sort", [True, False])
def test_regression_whitelist_methods(raw_frame, op, level, axis, skipna, sort):
def test_regression_allowlist_methods(raw_frame, op, level, axis, skipna, sort):
# GH6944
# GH 17537
# explicitly test the whitelist methods
# explicitly test the allowlist methods

if axis == 0:
frame = raw_frame
Expand All @@ -213,11 +213,11 @@ def test_regression_whitelist_methods(raw_frame, op, level, axis, skipna, sort):
tm.assert_frame_equal(result, expected)


def test_groupby_blacklist(df_letters):
def test_groupby_blocklist(df_letters):
df = df_letters
s = df_letters.floats

blacklist = [
blocklist = [
"eval",
"query",
"abs",
Expand All @@ -234,9 +234,9 @@ def test_groupby_blacklist(df_letters):
]
to_methods = [method for method in dir(df) if method.startswith("to_")]

blacklist.extend(to_methods)
blocklist.extend(to_methods)

for bl in blacklist:
for bl in blocklist:
for obj in (df, s):
gb = obj.groupby(df.letters)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/transform/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def test_cython_transform_frame(op, args, targop):
# dict(by=['int','string'])]:

gb = df.groupby(**gb_target)
# whitelisted methods set the selection before applying
# allowlisted methods set the selection before applying
# bit a of hack to make sure the cythonized shift
# is equivalent to pre 0.17.1 behavior
if op == "shift":
Expand Down