Skip to content

Commit d000e70

Browse files
authored
Fix language style (#34924)
1 parent 45952c7 commit d000e70

File tree

8 files changed

+52
-52
lines changed

8 files changed

+52
-52
lines changed

asv_bench/benchmarks/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from .pandas_vb_common import tm
1818

19-
method_blacklist = {
19+
method_blocklist = {
2020
"object": {
2121
"median",
2222
"prod",
@@ -403,7 +403,7 @@ class GroupByMethods:
403403
]
404404

405405
def setup(self, dtype, method, application):
406-
if method in method_blacklist.get(dtype, {}):
406+
if method in method_blocklist.get(dtype, {}):
407407
raise NotImplementedError # skip benchmark
408408
ngroups = 1000
409409
size = ngroups * 2

ci/code_checks.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,19 @@ fi
248248
### CODE ###
249249
if [[ -z "$CHECK" || "$CHECK" == "code" ]]; then
250250

251-
MSG='Check import. No warnings, and blacklist some optional dependencies' ; echo $MSG
251+
MSG='Check import. No warnings, and blocklist some optional dependencies' ; echo $MSG
252252
python -W error -c "
253253
import sys
254254
import pandas
255255
256-
blacklist = {'bs4', 'gcsfs', 'html5lib', 'http', 'ipython', 'jinja2', 'hypothesis',
256+
blocklist = {'bs4', 'gcsfs', 'html5lib', 'http', 'ipython', 'jinja2', 'hypothesis',
257257
'lxml', 'matplotlib', 'numexpr', 'openpyxl', 'py', 'pytest', 's3fs', 'scipy',
258258
'tables', 'urllib.request', 'xlrd', 'xlsxwriter', 'xlwt'}
259259
260260
# GH#28227 for some of these check for top-level modules, while others are
261261
# more specific (e.g. urllib.request)
262262
import_mods = set(m.split('.')[0] for m in sys.modules) | set(sys.modules)
263-
mods = blacklist & import_mods
263+
mods = blocklist & import_mods
264264
if mods:
265265
sys.stderr.write('err: pandas should not import: {}\n'.format(', '.join(mods)))
266266
sys.exit(len(mods))

doc/source/whatsnew/v0.14.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Enhancements
131131

132132
- Implemented ``sem`` (standard error of the mean) operation for ``Series``,
133133
``DataFrame``, ``Panel``, and ``Groupby`` (:issue:`6897`)
134-
- Add ``nlargest`` and ``nsmallest`` to the ``Series`` ``groupby`` whitelist,
134+
- Add ``nlargest`` and ``nsmallest`` to the ``Series`` ``groupby`` allowlist,
135135
which means you can now use these methods on a ``SeriesGroupBy`` object
136136
(:issue:`7053`).
137137
- All offsets ``apply``, ``rollforward`` and ``rollback`` can now handle ``np.datetime64``, previously results in ``ApplyTypeError`` (:issue:`7452`)

pandas/core/groupby/base.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Provide basic components for groupby. These definitions
3-
hold the whitelist of methods that are exposed on the
3+
hold the allowlist of methods that are exposed on the
44
SeriesGroupBy and the DataFrameGroupBy objects.
55
"""
66
import collections
@@ -53,7 +53,7 @@ def _gotitem(self, key, ndim, subset=None):
5353
# forwarding methods from NDFrames
5454
plotting_methods = frozenset(["plot", "hist"])
5555

56-
common_apply_whitelist = (
56+
common_apply_allowlist = (
5757
frozenset(
5858
[
5959
"quantile",
@@ -72,9 +72,9 @@ def _gotitem(self, key, ndim, subset=None):
7272
| plotting_methods
7373
)
7474

75-
series_apply_whitelist = (
75+
series_apply_allowlist = (
7676
(
77-
common_apply_whitelist
77+
common_apply_allowlist
7878
| {
7979
"nlargest",
8080
"nsmallest",
@@ -84,13 +84,13 @@ def _gotitem(self, key, ndim, subset=None):
8484
)
8585
) | frozenset(["dtype", "unique"])
8686

87-
dataframe_apply_whitelist = common_apply_whitelist | frozenset(["dtypes", "corrwith"])
87+
dataframe_apply_allowlist = common_apply_allowlist | frozenset(["dtypes", "corrwith"])
8888

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

93-
cython_cast_blacklist = frozenset(["rank", "count", "size", "idxmin", "idxmax"])
93+
cython_cast_blocklist = frozenset(["rank", "count", "size", "idxmin", "idxmax"])
9494

9595
# List of aggregation/reduction functions.
9696
# These map each group to a single numeric value
@@ -186,4 +186,4 @@ def _gotitem(self, key, ndim, subset=None):
186186
# Valid values of `name` for `groupby.transform(name)`
187187
# NOTE: do NOT edit this directly. New additions should be inserted
188188
# into the appropriate list above.
189-
transform_kernel_whitelist = reduction_kernels | transformation_kernels
189+
transform_kernel_allowlist = reduction_kernels | transformation_kernels

pandas/core/groupby/generic.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ def prop(self):
121121
return property(prop)
122122

123123

124-
def pin_whitelisted_properties(klass: Type[FrameOrSeries], whitelist: FrozenSet[str]):
124+
def pin_allowlisted_properties(klass: Type[FrameOrSeries], allowlist: FrozenSet[str]):
125125
"""
126-
Create GroupBy member defs for DataFrame/Series names in a whitelist.
126+
Create GroupBy member defs for DataFrame/Series names in a allowlist.
127127
128128
Parameters
129129
----------
130130
klass : DataFrame or Series class
131131
class where members are defined.
132-
whitelist : frozenset[str]
132+
allowlist : frozenset[str]
133133
Set of names of klass methods to be constructed
134134
135135
Returns
@@ -143,7 +143,7 @@ class decorator
143143
"""
144144

145145
def pinner(cls):
146-
for name in whitelist:
146+
for name in allowlist:
147147
if hasattr(cls, name):
148148
# don't override anything that was explicitly defined
149149
# in the base class
@@ -157,9 +157,9 @@ def pinner(cls):
157157
return pinner
158158

159159

160-
@pin_whitelisted_properties(Series, base.series_apply_whitelist)
160+
@pin_allowlisted_properties(Series, base.series_apply_allowlist)
161161
class SeriesGroupBy(GroupBy[Series]):
162-
_apply_whitelist = base.series_apply_whitelist
162+
_apply_allowlist = base.series_apply_allowlist
163163

164164
def _iterate_slices(self) -> Iterable[Series]:
165165
yield self._selected_obj
@@ -473,7 +473,7 @@ def transform(self, func, *args, engine="cython", engine_kwargs=None, **kwargs):
473473
func, *args, engine=engine, engine_kwargs=engine_kwargs, **kwargs
474474
)
475475

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

837837

838-
@pin_whitelisted_properties(DataFrame, base.dataframe_apply_whitelist)
838+
@pin_allowlisted_properties(DataFrame, base.dataframe_apply_allowlist)
839839
class DataFrameGroupBy(GroupBy[DataFrame]):
840840

841-
_apply_whitelist = base.dataframe_apply_whitelist
841+
_apply_allowlist = base.dataframe_apply_allowlist
842842

843843
_agg_examples_doc = dedent(
844844
"""
@@ -1456,7 +1456,7 @@ def transform(self, func, *args, engine="cython", engine_kwargs=None, **kwargs):
14561456
func, *args, engine=engine, engine_kwargs=engine_kwargs, **kwargs
14571457
)
14581458

1459-
elif func not in base.transform_kernel_whitelist:
1459+
elif func not in base.transform_kernel_allowlist:
14601460
msg = f"'{func}' is not a valid function name for transform(name)"
14611461
raise ValueError(msg)
14621462
elif func in base.cythonized_kernels:

pandas/core/groupby/groupby.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def _group_selection_context(groupby):
475475

476476
class _GroupBy(PandasObject, SelectionMixin, Generic[FrameOrSeries]):
477477
_group_selection = None
478-
_apply_whitelist: FrozenSet[str] = frozenset()
478+
_apply_allowlist: FrozenSet[str] = frozenset()
479479

480480
def __init__(
481481
self,
@@ -689,7 +689,7 @@ def _set_result_index_ordered(self, result):
689689
return result
690690

691691
def _dir_additions(self):
692-
return self.obj._dir_additions() | self._apply_whitelist
692+
return self.obj._dir_additions() | self._apply_allowlist
693693

694694
def __getattr__(self, attr: str):
695695
if attr in self._internal_names_set:
@@ -729,7 +729,7 @@ def pipe(self, func, *args, **kwargs):
729729
plot = property(GroupByPlot)
730730

731731
def _make_wrapper(self, name):
732-
assert name in self._apply_whitelist
732+
assert name in self._apply_allowlist
733733

734734
self._set_group_selection()
735735

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

949949
def _cython_transform(self, how: str, numeric_only: bool = True, **kwargs):
950950
output: Dict[base.OutputKey, np.ndarray] = {}

pandas/tests/groupby/test_whitelist.py renamed to pandas/tests/groupby/test_allowlist.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
]
3232
AGG_FUNCTIONS_WITH_SKIPNA = ["skew", "mad"]
3333

34-
df_whitelist = [
34+
df_allowlist = [
3535
"quantile",
3636
"fillna",
3737
"mad",
@@ -50,12 +50,12 @@
5050
]
5151

5252

53-
@pytest.fixture(params=df_whitelist)
54-
def df_whitelist_fixture(request):
53+
@pytest.fixture(params=df_allowlist)
54+
def df_allowlist_fixture(request):
5555
return request.param
5656

5757

58-
s_whitelist = [
58+
s_allowlist = [
5959
"quantile",
6060
"fillna",
6161
"mad",
@@ -78,8 +78,8 @@ def df_whitelist_fixture(request):
7878
]
7979

8080

81-
@pytest.fixture(params=s_whitelist)
82-
def s_whitelist_fixture(request):
81+
@pytest.fixture(params=s_allowlist)
82+
def s_allowlist_fixture(request):
8383
return request.param
8484

8585

@@ -119,22 +119,22 @@ def df_letters():
119119
return df
120120

121121

122-
@pytest.mark.parametrize("whitelist", [df_whitelist, s_whitelist])
123-
def test_groupby_whitelist(df_letters, whitelist):
122+
@pytest.mark.parametrize("allowlist", [df_allowlist, s_allowlist])
123+
def test_groupby_allowlist(df_letters, allowlist):
124124
df = df_letters
125-
if whitelist == df_whitelist:
125+
if allowlist == df_allowlist:
126126
# dataframe
127127
obj = df_letters
128128
else:
129129
obj = df_letters["floats"]
130130

131131
gb = obj.groupby(df.letters)
132132

133-
assert set(whitelist) == set(gb._apply_whitelist)
133+
assert set(allowlist) == set(gb._apply_allowlist)
134134

135135

136-
def check_whitelist(obj, df, m):
137-
# check the obj for a particular whitelist m
136+
def check_allowlist(obj, df, m):
137+
# check the obj for a particular allowlist m
138138

139139
gb = obj.groupby(df.letters)
140140

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

157157

158-
def test_groupby_series_whitelist(df_letters, s_whitelist_fixture):
159-
m = s_whitelist_fixture
158+
def test_groupby_series_allowlist(df_letters, s_allowlist_fixture):
159+
m = s_allowlist_fixture
160160
df = df_letters
161-
check_whitelist(df.letters, df, m)
161+
check_allowlist(df.letters, df, m)
162162

163163

164-
def test_groupby_frame_whitelist(df_letters, df_whitelist_fixture):
165-
m = df_whitelist_fixture
164+
def test_groupby_frame_allowlist(df_letters, df_allowlist_fixture):
165+
m = df_allowlist_fixture
166166
df = df_letters
167-
check_whitelist(df, df, m)
167+
check_allowlist(df, df, m)
168168

169169

170170
@pytest.fixture
@@ -187,10 +187,10 @@ def raw_frame():
187187
@pytest.mark.parametrize("axis", [0, 1])
188188
@pytest.mark.parametrize("skipna", [True, False])
189189
@pytest.mark.parametrize("sort", [True, False])
190-
def test_regression_whitelist_methods(raw_frame, op, level, axis, skipna, sort):
190+
def test_regression_allowlist_methods(raw_frame, op, level, axis, skipna, sort):
191191
# GH6944
192192
# GH 17537
193-
# explicitly test the whitelist methods
193+
# explicitly test the allowlist methods
194194

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

215215

216-
def test_groupby_blacklist(df_letters):
216+
def test_groupby_blocklist(df_letters):
217217
df = df_letters
218218
s = df_letters.floats
219219

220-
blacklist = [
220+
blocklist = [
221221
"eval",
222222
"query",
223223
"abs",
@@ -234,9 +234,9 @@ def test_groupby_blacklist(df_letters):
234234
]
235235
to_methods = [method for method in dir(df) if method.startswith("to_")]
236236

237-
blacklist.extend(to_methods)
237+
blocklist.extend(to_methods)
238238

239-
for bl in blacklist:
239+
for bl in blocklist:
240240
for obj in (df, s):
241241
gb = obj.groupby(df.letters)
242242

pandas/tests/groupby/transform/test_transform.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ def test_cython_transform_frame(op, args, targop):
728728
# dict(by=['int','string'])]:
729729

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

0 commit comments

Comments
 (0)