Skip to content

Commit ff1fa4e

Browse files
mroeschkejreback
authored andcommitted
CLN/STYLE: Lint comprehensions (#22075)
1 parent 0c58a82 commit ff1fa4e

31 files changed

+88
-107
lines changed

ci/environment-dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dependencies:
66
- Cython>=0.28.2
77
- NumPy
88
- flake8
9+
- flake8-comprehensions
910
- moto
1011
- pytest>=3.1
1112
- python-dateutil>=2.5.0

ci/lint.sh

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,42 @@ if [ "$LINT" ]; then
1010

1111
# pandas/_libs/src is C code, so no need to search there.
1212
echo "Linting *.py"
13-
flake8 pandas --filename=*.py --exclude pandas/_libs/src
13+
flake8 pandas --filename=*.py --exclude pandas/_libs/src --ignore=C405,C406,C408,C409,C410,E402,E731,E741,W503
1414
if [ $? -ne "0" ]; then
1515
RET=1
1616
fi
1717
echo "Linting *.py DONE"
1818

1919
echo "Linting setup.py"
20-
flake8 setup.py
20+
flake8 setup.py --ignore=C405,C406,C408,C409,C410,E402,E731,E741,W503
2121
if [ $? -ne "0" ]; then
2222
RET=1
2323
fi
2424
echo "Linting setup.py DONE"
2525

2626
echo "Linting asv_bench/benchmarks/"
27-
flake8 asv_bench/benchmarks/ --exclude=asv_bench/benchmarks/*.py --ignore=F811
27+
flake8 asv_bench/benchmarks/ --exclude=asv_bench/benchmarks/*.py --ignore=F811,C405,C406,C408,C409,C410
2828
if [ $? -ne "0" ]; then
2929
RET=1
3030
fi
3131
echo "Linting asv_bench/benchmarks/*.py DONE"
3232

3333
echo "Linting scripts/*.py"
34-
flake8 scripts --filename=*.py
34+
flake8 scripts --filename=*.py --ignore=C405,C406,C408,C409,C410,E402,E731,E741,W503
3535
if [ $? -ne "0" ]; then
3636
RET=1
3737
fi
3838
echo "Linting scripts/*.py DONE"
3939

4040
echo "Linting doc scripts"
41-
flake8 doc/make.py doc/source/conf.py
41+
flake8 doc/make.py doc/source/conf.py --ignore=C405,C406,C408,C409,C410,E402,E731,E741,W503
4242
if [ $? -ne "0" ]; then
4343
RET=1
4444
fi
4545
echo "Linting doc scripts DONE"
4646

4747
echo "Linting *.pyx"
48-
flake8 pandas --filename=*.pyx --select=E501,E302,E203,E111,E114,E221,E303,E128,E231,E126,E265,E305,E301,E127,E261,E271,E129,W291,E222,E241,E123,F403
48+
flake8 pandas --filename=*.pyx --select=E501,E302,E203,E111,E114,E221,E303,E128,E231,E126,E265,E305,E301,E127,E261,E271,E129,W291,E222,E241,E123,F403,C400,C401,C402,C403,C404,C407,C411
4949
if [ $? -ne "0" ]; then
5050
RET=1
5151
fi
@@ -131,19 +131,6 @@ if [ "$LINT" ]; then
131131
fi
132132
echo "Check for non-standard imports DONE"
133133

134-
echo "Check for use of lists instead of generators in built-in Python functions"
135-
136-
# Example: Avoid `any([i for i in some_iterator])` in favor of `any(i for i in some_iterator)`
137-
#
138-
# Check the following functions:
139-
# any(), all(), sum(), max(), min(), list(), dict(), set(), frozenset(), tuple(), str.join()
140-
grep -R --include="*.py*" -E "[^_](any|all|sum|max|min|list|dict|set|frozenset|tuple|join)\(\[.* for .* in .*\]\)" pandas
141-
142-
if [ $? = "0" ]; then
143-
RET=1
144-
fi
145-
echo "Check for use of lists instead of generators in built-in Python functions DONE"
146-
147134
echo "Check for incorrect sphinx directives"
148135
SPHINX_DIRECTIVES=$(echo \
149136
"autosummary|contents|currentmodule|deprecated|function|image|"\

ci/travis-27.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies:
99
- fastparquet
1010
- feather-format
1111
- flake8=3.4.1
12+
- flake8-comprehensions
1213
- gcsfs
1314
- html5lib
1415
- ipython

pandas/core/arrays/interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ def _concat_same_type(cls, to_concat):
600600
-------
601601
IntervalArray
602602
"""
603-
closed = set(interval.closed for interval in to_concat)
603+
closed = {interval.closed for interval in to_concat}
604604
if len(closed) != 1:
605605
raise ValueError("Intervals must all be closed on the same side.")
606606
closed = closed.pop()

pandas/core/common.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,7 @@ def dict_compat(d):
307307
dict
308308
309309
"""
310-
return dict((maybe_box_datetimelike(key), value)
311-
for key, value in iteritems(d))
310+
return {maybe_box_datetimelike(key): value for key, value in iteritems(d)}
312311

313312

314313
def standardize_mapping(into):

pandas/core/dtypes/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
is_named_tuple, is_array_like, is_decimal, is_complex, is_interval)
2222

2323

24-
_POSSIBLY_CAST_DTYPES = set([np.dtype(t).name
25-
for t in ['O', 'int8', 'uint8', 'int16', 'uint16',
26-
'int32', 'uint32', 'int64', 'uint64']])
24+
_POSSIBLY_CAST_DTYPES = {np.dtype(t).name
25+
for t in ['O', 'int8', 'uint8', 'int16', 'uint16',
26+
'int32', 'uint32', 'int64', 'uint64']}
2727

2828
_NS_DTYPE = conversion.NS_DTYPE
2929
_TD_DTYPE = conversion.TD_DTYPE

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8840,7 +8840,7 @@ def describe_1d(data):
88408840
ldesc = [describe_1d(s) for _, s in data.iteritems()]
88418841
# set a convenient order for rows
88428842
names = []
8843-
ldesc_indexes = sorted([x.index for x in ldesc], key=len)
8843+
ldesc_indexes = sorted((x.index for x in ldesc), key=len)
88448844
for idxnames in ldesc_indexes:
88458845
for name in idxnames:
88468846
if name not in names:

pandas/core/groupby/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ def _gotitem(self, key, ndim, subset=None):
4343

4444
# we need to make a shallow copy of ourselves
4545
# with the same groupby
46-
kwargs = dict([(attr, getattr(self, attr))
47-
for attr in self._attributes])
46+
kwargs = {attr: getattr(self, attr) for attr in self._attributes}
4847
self = self.__class__(subset,
4948
groupby=self._groupby[key],
5049
parent=self,

pandas/core/indexes/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ def _get_consensus_names(indexes):
147147

148148
# find the non-none names, need to tupleify to make
149149
# the set hashable, then reverse on return
150-
consensus_names = set(tuple(i.names) for i in indexes
151-
if com._any_not_none(*i.names))
150+
consensus_names = {tuple(i.names) for i in indexes
151+
if com._any_not_none(*i.names)}
152152
if len(consensus_names) == 1:
153153
return list(list(consensus_names)[0])
154154
return [None] * indexes[0].nlevels

pandas/core/indexes/multi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,8 @@ def f(k, stringify):
903903
if stringify and not isinstance(k, compat.string_types):
904904
k = str(k)
905905
return k
906-
key = tuple([f(k, stringify)
907-
for k, stringify in zip(key, self._have_mixed_levels)])
906+
key = tuple(f(k, stringify)
907+
for k, stringify in zip(key, self._have_mixed_levels))
908908
return hash_tuple(key)
909909

910910
@Appender(Index.duplicated.__doc__)

0 commit comments

Comments
 (0)