-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
CLN: Replace comprehensions list/set/dict functions with corresponding symbols #18383
Conversation
5aae05b
to
ce932a6
Compare
Codecov Report
@@ Coverage Diff @@
## master #18383 +/- ##
==========================================
- Coverage 91.36% 91.36% -0.01%
==========================================
Files 164 164
Lines 49718 49814 +96
==========================================
+ Hits 45426 45513 +87
- Misses 4292 4301 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18383 +/- ##
==========================================
- Coverage 91.35% 91.33% -0.03%
==========================================
Files 163 163
Lines 49695 49695
==========================================
- Hits 45401 45391 -10
- Misses 4294 4304 +10
Continue to review full report at Codecov.
|
ce932a6
to
c49a325
Compare
ping all green |
c49a325
to
b88f5e8
Compare
ci/lint.sh
Outdated
|
||
# Example: Avoid `list(i for i in some_iterator)` in favor of `[i for i in some_iterator]` | ||
# | ||
# Check the following functions: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don''t you need to specify the directory?
e.g. on current master
(pandas) bash-3.2$ grep -R --include="*.py*" -E "(list|dict|[^frozen]set)\([^\{)=]* for .* in [^}]*\)" pandas
pandas/_libs/parsers.pyx: dtypes = set(a.dtype for a in arrs)
pandas/_version.py: tags = set(r for r in refs if re.search(r'\d', r))
pandas/core/dtypes/concat.py: fill_values = set(c.fill_value for c in to_concat)
pandas/core/groupby.py: names = set(v.name for v in values)
pandas/core/indexes/base.py: names = set(obj.name for obj in to_concat)
pandas/core/indexes/interval.py: if not len(set(i.closed for i in to_concat if len(i))) == 1:
pandas/core/internals.py: ndim = set(b.ndim for b in blocks)
pandas/core/internals.py: if len(set(b.dtype for b in blocks)) != 1:
pandas/core/reshape/concat.py: if not len(set(idx.nlevels for idx in indexes)) == 1:
pandas/io/parsers.py: return set(i for i, name in enumerate(names)
pandas/io/pytables.py: axis = list(set(t.non_index_axes[0][0] for t in tbls))[0]
pandas/tests/groupby/test_whitelist.py: results = set(v for v in dir(grp) if not v.startswith('_'))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wanting to lint the entire project (including python scripts in the other directories, e.g docs) and Travis was linting everything.
I can change it to just lint the pandas directory if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no u need to specify a dir . is ok
the command doesn’t work atm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes it looks my grep is too restrictive here.
Admittedly my grep-foo is a bit too weak for this lint. I am not sure how to write a grep to catching matching parenthesis, list|set|dict(
to the matching )
, and there are edge cases that are hard to catch, e.g. list(set comprehension)
is okay, dict()
can accept =
that is assigned to a list comprehension, etc.
I can create a new issue for this unless someone with more grep experience can chime in.
b88f5e8
to
f6f4006
Compare
f6f4006
to
371c22f
Compare
I created issue #18464 to follow up on the lint statement for this pattern. |
@@ -606,11 +606,11 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose): | |||
if verbose: | |||
print("keywords are unexpanded, not using") | |||
raise NotThisMethod("unexpanded keywords, not a git-archive tarball") | |||
refs = set(r.strip() for r in refnames.strip("()").split(",")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is good idea to clean up versioneer since this is just a file from another project. Maybe this should be excluded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it probably doesn't matter much. we already replace some formatting code here as well.
thanks @mroeschke |
git diff upstream/master -u -- "*.py" | flake8 --diff
xref @jreback's comment and @maxim-lian comment, replace the following where appropriate:
list(x for x in iterator)
-->[x for x in iterator]
set(x for x in iterator)
-->{x for x in iterator}
dict((x,x) for x in iterator)
-->{x: x for x in iterator}