-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MAINT Use np.full when possible #12379
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
Changes from 4 commits
5a1e7b3
de37bc5
2da8562
95fa27f
d376dad
fec1fa0
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 |
---|---|---|
|
@@ -231,7 +231,7 @@ def create_artists(self, legend, orig_handle, | |
xdata, xdata_marker = self.get_xdata(legend, xdescent, ydescent, | ||
width, height, fontsize) | ||
|
||
ydata = ((height - ydescent) / 2.) * np.ones(xdata.shape, float) | ||
ydata = np.full(xdata.shape, ((height - ydescent) / 2), float) | ||
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.
|
||
legline = Line2D(xdata, ydata) | ||
|
||
self.update_prop(legline, orig_handle, legend) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,7 +312,7 @@ def make_compound_path_from_polys(cls, XY): | |
stride = numsides + 1 | ||
nverts = numpolys * stride | ||
verts = np.zeros((nverts, 2)) | ||
codes = np.ones(nverts, int) * cls.LINETO | ||
codes = np.full(nverts, cls.LINETO, dtype=cls.code_type) | ||
codes[0::stride] = cls.MOVETO | ||
codes[numsides::stride] = cls.CLOSEPOLY | ||
for i in range(numsides): | ||
|
@@ -552,7 +552,8 @@ def interpolated(self, steps): | |
vertices = simple_linear_interpolation(self.vertices, steps) | ||
codes = self.codes | ||
if codes is not None: | ||
new_codes = Path.LINETO * np.ones(((len(codes) - 1) * steps + 1, )) | ||
new_codes = np.full(((len(codes) - 1) * steps + 1, ), Path.LINETO, | ||
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. can pass the shape as scalar instead of 1-tuple |
||
dtype=self.code_type) | ||
new_codes[0::steps] = codes | ||
else: | ||
new_codes = None | ||
|
@@ -802,7 +803,7 @@ def unit_circle_righthalf(cls): | |
|
||
float) | ||
|
||
codes = cls.CURVE4 * np.ones(14) | ||
codes = np.full(14, cls.CURVE4, dtype=cls.code_type) | ||
codes[0] = cls.MOVETO | ||
codes[-1] = cls.CLOSEPOLY | ||
|
||
|
@@ -864,7 +865,7 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False): | |
if is_wedge: | ||
length = n * 3 + 4 | ||
vertices = np.zeros((length, 2), float) | ||
codes = cls.CURVE4 * np.ones((length, ), cls.code_type) | ||
codes = np.full((length, ), cls.CURVE4, dtype=cls.code_type) | ||
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. can pass shape as scalar |
||
vertices[1] = [xA[0], yA[0]] | ||
codes[0:2] = [cls.MOVETO, cls.LINETO] | ||
codes[-2:] = [cls.LINETO, cls.CLOSEPOLY] | ||
|
@@ -873,7 +874,7 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False): | |
else: | ||
length = n * 3 + 1 | ||
vertices = np.empty((length, 2), float) | ||
codes = cls.CURVE4 * np.ones((length, ), cls.code_type) | ||
codes = np.full((length, ), cls.CURVE4, dtype=cls.code_type) | ||
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. can pass shape as scalar |
||
vertices[0] = [xA[0], yA[0]] | ||
codes[0] = cls.MOVETO | ||
vertex_offset = 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,7 @@ def refine_triangulation(self, return_tri_index=False, subdiv=3): | |
# We have to initialize found_index with -1 because some nodes | ||
# may very well belong to no triangle at all, e.g., in case of | ||
# Delaunay Triangulation with DuplicatePointWarning. | ||
found_index = - np.ones(refi_npts, dtype=np.int32) | ||
found_index = np.full(refi_npts, -1, dtype=np.int32) | ||
tri_mask = self._triangulation.mask | ||
if tri_mask is None: | ||
found_index[refi_triangles] = np.repeat(ancestors, | ||
|
@@ -243,7 +243,7 @@ def _refine_triangulation_once(triangulation, ancestors=None): | |
np.arange(ntri, dtype=np.int32)])) | ||
edge_apexes = np.ravel(np.vstack([np.zeros(ntri, dtype=np.int32), | ||
np.ones(ntri, dtype=np.int32), | ||
np.ones(ntri, dtype=np.int32)*2])) | ||
np.full(ntri, 2, dtype=np.int32)])) | ||
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. Perhaps replace the previous two lines to use np.full too? Looks nicer :) Also I think the whole thing is just
right? |
||
edge_neighbors = neighbors[edge_elems, edge_apexes] | ||
mask_masters = (edge_elems > edge_neighbors) | ||
|
||
|
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.
Probably should be Path.code_type.