Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 184225b

Browse filesBrowse files
timhoffmMeeseeksDev[bot]
authored andcommitted
Backport PR #14488: Make sure EventCollection doesn't modify input in-place
1 parent 9a5473d commit 184225b
Copy full SHA for 184225b

File tree

Expand file treeCollapse file tree

2 files changed

+13
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-3
lines changed

‎lib/matplotlib/collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/collections.py
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,12 +1470,15 @@ def __init__(self,
14701470
14711471
.. plot:: gallery/lines_bars_and_markers/eventcollection_demo.py
14721472
"""
1473-
1473+
if positions is None:
1474+
raise ValueError('positions must be an array-like object')
1475+
# Force a copy of positions
1476+
positions = np.array(positions, copy=True)
14741477
segment = (lineoffset + linelength / 2.,
14751478
lineoffset - linelength / 2.)
1476-
if positions is None or len(positions) == 0:
1479+
if positions.size == 0:
14771480
segments = []
1478-
elif hasattr(positions, 'ndim') and positions.ndim > 1:
1481+
elif positions.ndim > 1:
14791482
raise ValueError('positions cannot be an array with more than '
14801483
'one dimension.')
14811484
elif (orientation is None or orientation.lower() == 'none' or

‎lib/matplotlib/tests/test_collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_collections.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,10 @@ def test_pathcollection_legend_elements():
721721
ax.add_artist(l)
722722

723723
fig.canvas.draw()
724+
725+
726+
def test_EventCollection_nosort():
727+
# Check that EventCollection doesn't modify input in place
728+
arr = np.array([3, 2, 1, 10])
729+
coll = EventCollection(arr)
730+
np.testing.assert_array_equal(arr, np.array([3, 2, 1, 10]))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.