Skip to content

np.concatenate cleanups. #15679

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

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/specialty_plots/radar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def _close_line(self, line):
x, y = line.get_data()
# FIXME: markers at x[0], y[0] get doubled-up
if x[0] != x[-1]:
x = np.concatenate((x, [x[0]]))
y = np.concatenate((y, [y[0]]))
x = np.append(x, x[0])
y = np.append(y, y[0])
line.set_data(x, y)

def set_varlabels(self, labels):
Expand Down
16 changes: 7 additions & 9 deletions lib/matplotlib/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,14 @@ def split_path_inout(path, inside, tolerance=0.01, reorder_inout=False):

ctl_points_old = ctl_points

concat = np.concatenate

iold = 0
i = 1

for ctl_points, command in path_iter:
iold = i
i += len(ctl_points) // 2
if inside(ctl_points[-2:]) != begin_inside:
bezier_path = concat([ctl_points_old[-2:], ctl_points])
bezier_path = np.concatenate([ctl_points_old[-2:], ctl_points])
break
ctl_points_old = ctl_points
else:
Expand All @@ -302,15 +300,15 @@ def split_path_inout(path, inside, tolerance=0.01, reorder_inout=False):
verts_right = right[:]

if path.codes is None:
path_in = Path(concat([path.vertices[:i], verts_left]))
path_out = Path(concat([verts_right, path.vertices[i:]]))
path_in = Path(np.concatenate([path.vertices[:i], verts_left]))
path_out = Path(np.concatenate([verts_right, path.vertices[i:]]))

else:
path_in = Path(concat([path.vertices[:iold], verts_left]),
concat([path.codes[:iold], codes_left]))
path_in = Path(np.concatenate([path.vertices[:iold], verts_left]),
np.concatenate([path.codes[:iold], codes_left]))

path_out = Path(concat([verts_right, path.vertices[i:]]),
concat([codes_right, path.codes[i:]]))
path_out = Path(np.concatenate([verts_right, path.vertices[i:]]),
np.concatenate([codes_right, path.codes[i:]]))

if reorder_inout and not begin_inside:
path_in, path_out = path_out, path_in
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,8 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,

if sides == 'twosided':
# center the frequency range at zero
freqs = np.concatenate((freqs[freqcenter:], freqs[:freqcenter]))
result = np.concatenate((result[freqcenter:, :],
result[:freqcenter, :]), 0)
freqs = np.roll(freqs, -freqcenter, axis=0)
result = np.roll(result, -freqcenter, axis=0)
elif not pad_to % 2:
# get the last value correctly, it is negative otherwise
freqs[-1] *= -1
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2342,8 +2342,7 @@ def transmute(self, x0, y0, width, height, mutation_size):
width, height,
mutation_size)
# Add a trailing vertex to allow us to close the polygon correctly
saw_vertices = np.concatenate([np.array(saw_vertices),
[saw_vertices[0]]], axis=0)
saw_vertices = np.concatenate([saw_vertices, [saw_vertices[0]]])
codes = ([Path.MOVETO] +
[Path.CURVE3, Path.CURVE3] * ((len(saw_vertices)-1)//2) +
[Path.CLOSEPOLY])
Expand Down
4 changes: 1 addition & 3 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ def test_minor(self, lims, expected_low_ticks):
else:
# subsample
_LogitHelper.assert_almost_equal(
np.sort(np.concatenate((major_ticks, minor_ticks))),
expected_ticks,
)
sorted([*major_ticks, *minor_ticks]), expected_ticks)

def test_minor_attr(self):
loc = mticker.LogitLocator(nbins=100)
Expand Down
32 changes: 8 additions & 24 deletions lib/mpl_toolkits/axisartist/angle_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,11 @@ def select_step_degree(dv):
second_limits_ = np.array(minsec_limits_) / 3600
second_factors = [3600.] * len(second_limits_)

degree_limits = np.concatenate([second_limits_,
minute_limits_,
degree_limits_])
degree_limits = [*second_limits_, *minute_limits_, *degree_limits_]
degree_steps = [*minsec_steps_, *minsec_steps_, *degree_steps_]
degree_factors = [*second_factors, *minute_factors, *degree_factors]

degree_steps = np.concatenate([minsec_steps_,
minsec_steps_,
degree_steps_])

degree_factors = np.concatenate([second_factors,
minute_factors,
degree_factors])

n = degree_limits.searchsorted(dv)
n = np.searchsorted(degree_limits, dv)
step = degree_steps[n]
factor = degree_factors[n]

Expand All @@ -54,19 +46,11 @@ def select_step_hour(dv):
second_limits_ = np.array(minsec_limits_) / 3600
second_factors = [3600.] * len(second_limits_)

hour_limits = np.concatenate([second_limits_,
minute_limits_,
hour_limits_])

hour_steps = np.concatenate([minsec_steps_,
minsec_steps_,
hour_steps_])

hour_factors = np.concatenate([second_factors,
minute_factors,
hour_factors])
hour_limits = [*second_limits_, *minute_limits_, *hour_limits_]
hour_steps = [*minsec_steps_, *minsec_steps_, *hour_steps_]
hour_factors = [*second_factors, *minute_factors, *hour_factors]

n = hour_limits.searchsorted(dv)
n = np.searchsorted(hour_limits, dv)
step = hour_steps[n]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work? n is an array still, but hour_steps is a list now, and I can't index a list with an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dv is a scalar (this is called by select_step, where it is immediately preceded by if dv > 1 / threshold_factor -- semantically, it is the distance between the axes bounds) so n is a scalar as well and the indexing is fine.

I guess technically it is an API break in that select_step_degree could have been called directly by someone passing dv as an array, but I don't think this is a real issue (and is clearly not how select_step_degree was designed to do).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/preceded/succeeded/, but I see what you mean.

factor = hour_factors[n]

Expand Down