-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: Lint for lists instead of generators in built-in Python functions #18335
Conversation
When I changed the dict function call to |
4936ffc
to
dabb815
Compare
asv_bench/benchmarks/frame_ctor.py
Outdated
@@ -132,7 +132,7 @@ def setup(self, offset, n_steps): | |||
offset = getattr(offsets, offset) | |||
self.idx = get_index_for_offset(offset(n_steps, **kwargs)) | |||
self.df = DataFrame(np.random.randn(len(self.idx), 10), index=self.idx) | |||
self.d = dict([(col, self.df[col]) for col in self.df.columns]) | |||
self.d = dict((col, self.df[col]) for col in self.df.columns) |
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.
could have all these be dict (or set, below) comprehensions now that py2.6 is unsupported
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.
So you mean {foo for foo in bar}
instead of set(foo for foo in bar)
? Sure I don't see why not. Maybe that can be a followup to this.
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.
dict(df.items())
should work here
Codecov Report
@@ Coverage Diff @@
## master #18335 +/- ##
==========================================
- Coverage 91.38% 91.36% -0.02%
==========================================
Files 164 164
Lines 49790 49790
==========================================
- Hits 45501 45492 -9
- Misses 4289 4298 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18335 +/- ##
==========================================
- Coverage 91.36% 91.34% -0.02%
==========================================
Files 164 164
Lines 49790 49790
==========================================
- Hits 45489 45480 -9
- Misses 4301 4310 +9
Continue to review full report at Codecov.
|
can you rebase |
asv_bench/benchmarks/frame_ctor.py
Outdated
@@ -132,7 +132,7 @@ def setup(self, offset, n_steps): | |||
offset = getattr(offsets, offset) | |||
self.idx = get_index_for_offset(offset(n_steps, **kwargs)) | |||
self.df = DataFrame(np.random.randn(len(self.idx), 10), index=self.idx) | |||
self.d = dict([(col, self.df[col]) for col in self.df.columns]) | |||
self.d = dict((col, self.df[col]) for col in self.df.columns) |
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.
dict(df.items())
should work here
asv_bench/benchmarks/io_bench.py
Outdated
@@ -202,7 +202,7 @@ class read_json_lines(object): | |||
def setup(self): | |||
self.N = 100000 | |||
self.C = 5 | |||
self.df = DataFrame(dict([('float{0}'.format(i), randn(self.N)) for i in range(self.C)])) | |||
self.df = DataFrame(dict(('float{0}'.format(i), randn(self.N)) for i in range(self.C))) | |||
self.df.to_json(self.fname,orient="records",lines=True) |
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.
could use the comprehension
{('float{0}'.format(i), randn(self.N)) for i in range(self.C))}
pandas/core/indexes/api.py
Outdated
@@ -101,7 +101,7 @@ def conv(i): | |||
|
|||
|
|||
def _sanitize_and_check(indexes): | |||
kinds = list(set([type(index) for index in indexes])) | |||
kinds = list(set(type(index) for index in indexes)) |
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.
this could be a set comprehension
{type(index) for index in indexes}
prob more of these as well
c91410f
to
3572626
Compare
Rebased. I can create a follow up issue/PR to replace instances of |
thanks! |
git diff upstream/master -u -- "*.py" | flake8 --diff
Continuation of #18276 plus a lint check for list comprehension in built-in Python functions. The grep will only catch list comprehensions on single lines though. I'm all ears for greps that can catch multi-line list comprehensions or a better grep in general.