-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MAINT Use list comprehension #12883
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
MAINT Use list comprehension #12883
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -606,10 +606,8 @@ def create_artists(self, legend, orig_handle, | |
leg_markerline = Line2D(xdata_marker, ydata[:len(xdata_marker)]) | ||
self.update_prop(leg_markerline, markerline, legend) | ||
|
||
leg_stemlines = [] | ||
for thisx, thisy in zip(xdata_marker, ydata): | ||
l = Line2D([thisx, thisx], [bottom, thisy]) | ||
leg_stemlines.append(l) | ||
leg_stemlines = [Line2D([thisx, thisx], [bottom, thisy]) | ||
for thisx, thisy in zip(xdata_marker, ydata)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "this" prefix doesn't add any information and just makes it harder to read. While you're at it, can you please change this to |
||
|
||
for lm, m in zip(leg_stemlines, stemlines): | ||
self.update_prop(lm, m, legend) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,14 +189,11 @@ def path_to_3d_segment_with_codes(path, zs=0, zdir='z'): | |
"""Convert a path to a 3D segment with path codes.""" | ||
|
||
zs = np.broadcast_to(zs, len(path)) | ||
seg = [] | ||
codes = [] | ||
pathsegs = path.iter_segments(simplify=False, curves=False) | ||
for (((x, y), code), z) in zip(pathsegs, zs): | ||
seg.append((x, y, z)) | ||
codes.append(code) | ||
seg, codes = zip( | ||
*[((x, y, z), code) for (((x, y), code), z) in zip(pathsegs, zs)]) | ||
seg3d = [juggle_axes(x, y, z, zdir) for (x, y, z) in seg] | ||
return seg3d, codes | ||
return seg3d, list(codes) | ||
|
||
|
||
def paths_to_3d_segments_with_codes(paths, zs=0, zdir='z'): | ||
|
@@ -205,13 +202,10 @@ def paths_to_3d_segments_with_codes(paths, zs=0, zdir= D208 39;z'): | |
""" | ||
|
||
zs = np.broadcast_to(zs, len(paths)) | ||
segments = [] | ||
codes_list = [] | ||
for path, pathz in zip(paths, zs): | ||
segs, codes = path_to_3d_segment_with_codes(path, pathz, zdir) | ||
segments.append(segs) | ||
codes_list.append(codes) | ||
return segments, codes_list | ||
segments, codes_list = zip( | ||
*[path_to_3d_segment_with_codes(path, pathz, zdir) | ||
for path, pathz in zip(paths, zs)]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to #11577, this should be faster, In [4]: sequence = list(zip(range(1000), range(1000)))
In [5]: %%timeit
...: x = []
...: y = []
...: for x_el, y_el in sequence:
...: x.append(x_el)
...: y.append(y_el)
...:
135 µs ± 498 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
In [6]: %%timeit
...: x, y = zip(*sequence)
...: x = list(x)
...: y = list(y)
...:
...:
49.2 µs ± 234 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is indeed a good performance improvement! However, it gets hard to read because there's too much going on. I propose to construct the list beforehand and give it a name. This should be equally fast.
|
||
return list(segments), list(codes_list) | ||
|
||
|
||
class Line3DCollection(LineCollection): | ||
|
Uh oh!
There was an error while loading. Please reload this page.