Skip to content

Commit 486e626

Browse files
mroeschkejbrockmendel
authored andcommitted
STYLE/LINT: Set literals (#22202)
* Style: Use set literals: * flake8: * Fix empty sets * Undo spaces
1 parent 776fed3 commit 486e626

38 files changed

+75
-80
lines changed

ci/lint.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,42 @@ if [ "$LINT" ]; then
1313
#E731, # do not assign a lambda expression, use a def
1414
#E741, # do not use variables named 'l', 'O', or 'I'
1515
#W503, # line break before binary operator
16-
#C405, # Unnecessary (list/tuple) literal - rewrite as a set literal.
1716
#C406, # Unnecessary (list/tuple) literal - rewrite as a dict literal.
1817
#C408, # Unnecessary (dict/list/tuple) call - rewrite as a literal.
1918
#C409, # Unnecessary (list/tuple) passed to tuple() - (remove the outer call to tuple()/rewrite as a tuple literal).
2019
#C410 # Unnecessary (list/tuple) passed to list() - (remove the outer call to list()/rewrite as a list literal).
2120

2221
# pandas/_libs/src is C code, so no need to search there.
2322
echo "Linting *.py"
24-
flake8 pandas --filename=*.py --exclude pandas/_libs/src --ignore=C405,C406,C408,C409,C410,E402,E731,E741,W503
23+
flake8 pandas --filename=*.py --exclude pandas/_libs/src --ignore=C406,C408,C409,C410,E402,E731,E741,W503
2524
if [ $? -ne "0" ]; then
2625
RET=1
2726
fi
2827
echo "Linting *.py DONE"
2928

3029
echo "Linting setup.py"
31-
flake8 setup.py --ignore=C405,C406,C408,C409,C410,E402,E731,E741,W503
30+
flake8 setup.py --ignore=C406,C408,C409,C410,E402,E731,E741,W503
3231
if [ $? -ne "0" ]; then
3332
RET=1
3433
fi
3534
echo "Linting setup.py DONE"
3635

3736
echo "Linting asv_bench/benchmarks/"
38-
flake8 asv_bench/benchmarks/ --exclude=asv_bench/benchmarks/*.py --ignore=F811,C405,C406,C408,C409,C410
37+
flake8 asv_bench/benchmarks/ --exclude=asv_bench/benchmarks/*.py --ignore=F811,C406,C408,C409,C410
3938
if [ $? -ne "0" ]; then
4039
RET=1
4140
fi
4241
echo "Linting asv_bench/benchmarks/*.py DONE"
4342

4443
echo "Linting scripts/*.py"
45-
flake8 scripts --filename=*.py --ignore=C405,C406,C408,C409,C410,E402,E731,E741,W503
44+
flake8 scripts --filename=*.py --ignore=C406,C408,C409,C410,E402,E731,E741,W503
4645
if [ $? -ne "0" ]; then
4746
RET=1
4847
fi
4948
echo "Linting scripts/*.py DONE"
5049

5150
echo "Linting doc scripts"
52-
flake8 doc/make.py doc/source/conf.py --ignore=C405,C406,C408,C409,C410,E402,E731,E741,W503
51+
flake8 doc/make.py doc/source/conf.py --ignore=C406,C408,C409,C410,E402,E731,E741,W503
5352
if [ $? -ne "0" ]; then
5453
RET=1
5554
fi

pandas/_libs/ops.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ def maybe_convert_bool(ndarray[object] arr,
260260
result = np.empty(n, dtype=np.uint8)
261261

262262
# the defaults
263-
true_vals = set(('True', 'TRUE', 'true'))
264-
false_vals = set(('False', 'FALSE', 'false'))
263+
true_vals = {'True', 'TRUE', 'true'}
264+
false_vals = {'False', 'FALSE', 'false'}
265265

266266
if true_values is not None:
267267
true_vals = true_vals | set(true_values)

pandas/_libs/tslibs/frequencies.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ _lite_rule_alias = {
124124
'us': 'U',
125125
'ns': 'N'}
126126

127-
_dont_uppercase = set(('MS', 'ms'))
127+
_dont_uppercase = {'MS', 'ms'}
128128

129129
# ----------------------------------------------------------------------
130130

pandas/_libs/tslibs/nattype.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ from util cimport (get_nat,
2323

2424
# ----------------------------------------------------------------------
2525
# Constants
26-
nat_strings = set(['NaT', 'nat', 'NAT', 'nan', 'NaN', 'NAN'])
26+
nat_strings = {'NaT', 'nat', 'NAT', 'nan', 'NaN', 'NAN'}
2727

2828
cdef int64_t NPY_NAT = get_nat()
2929
iNaT = NPY_NAT # python-visible constant

pandas/_libs/tslibs/offsets.pyx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,10 @@ def _validate_business_time(t_input):
252252
# ---------------------------------------------------------------------
253253
# Constructor Helpers
254254

255-
relativedelta_kwds = set([
256-
'years', 'months', 'weeks', 'days',
257-
'year', 'month', 'day', 'weekday',
258-
'hour', 'minute', 'second', 'microsecond',
259-
'nanosecond', 'nanoseconds',
260-
'hours', 'minutes', 'seconds', 'microseconds'])
255+
relativedelta_kwds = {'years', 'months', 'weeks', 'days', 'year', 'month',
256+
'day', 'weekday', 'hour', 'minute', 'second',
257+
'microsecond', 'nanosecond', 'nanoseconds', 'hours',
258+
'minutes', 'seconds', 'microseconds'}
261259

262260

263261
def _determine_offset(kwds):

pandas/_libs/tslibs/period.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,6 @@ def _validate_end_alias(how):
19731973
'START': 'S', 'FINISH': 'E',
19741974
'BEGIN': 'S', 'END': 'E'}
19751975
how = how_dict.get(str(how).upper())
1976-
if how not in set(['S', 'E']):
1976+
if how not in {'S', 'E'}:
19771977
raise ValueError('How must be one of S or E')
19781978
return how

pandas/core/arrays/interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from . import ExtensionArray, Categorical
2727

28-
_VALID_CLOSED = set(['left', 'right', 'both', 'neither'])
28+
_VALID_CLOSED = {'left', 'right', 'both', 'neither'}
2929
_interval_shared_docs = {}
3030
_shared_docs_kwargs = dict(
3131
klass='IntervalArray',

pandas/core/computation/expressions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
# the set of dtypes that we will allow pass to numexpr
2626
_ALLOWED_DTYPES = {
27-
'evaluate': set(['int64', 'int32', 'float64', 'float32', 'bool']),
28-
'where': set(['int64', 'float64', 'bool'])
27+
'evaluate': {'int64', 'int32', 'float64', 'float32', 'bool'},
28+
'where': {'int64', 'float64', 'bool'}
2929
}
3030

3131
# the minimum prod shape that we will use numexpr
@@ -81,7 +81,7 @@ def _can_use_numexpr(op, op_str, a, b, dtype_check):
8181
return False
8282
dtypes |= set(s.index)
8383
elif isinstance(o, np.ndarray):
84-
dtypes |= set([o.dtype.name])
84+
dtypes |= {o.dtype.name}
8585

8686
# allowed are a superset
8787
if not len(dtypes) or _ALLOWED_DTYPES[dtype_check] >= dtypes:

pandas/core/dtypes/concat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ def is_nonempty(x):
188188
typs = get_dtype_kinds(to_concat)
189189
if len(typs) != 1:
190190

191-
if (not len(typs - set(['i', 'u', 'f'])) or
192-
not len(typs - set(['bool', 'i', 'u']))):
191+
if (not len(typs - {'i', 'u', 'f'}) or
192+
not len(typs - {'bool', 'i', 'u'})):
193193
# let numpy coerce
194194
pass
195195
else:
@@ -600,7 +600,7 @@ def convert_sparse(x, axis):
600600
to_concat = [convert_sparse(x, axis) for x in to_concat]
601601
result = np.concatenate(to_concat, axis=axis)
602602

603-
if not len(typs - set(['sparse', 'f', 'i'])):
603+
if not len(typs - {'sparse', 'f', 'i'}):
604604
# sparsify if inputs are sparse and dense numerics
605605
# first sparse input's fill_value and SparseIndex is used
606606
result = SparseArray(result.ravel(), fill_value=fill_values[0],

pandas/core/groupby/grouper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
481481
if key.key is None:
482482
return grouper, [], obj
483483
else:
484-
return grouper, set([key.key]), obj
484+
return grouper, {key.key}, obj
485485

486486
# already have a BaseGrouper, just return it
487487
elif isinstance(key, BaseGrouper):

0 commit comments

Comments
 (0)