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 6ba2651

Browse filesBrowse files
authored
Merge pull request #14488 from dstansby/event-coll-inplac
Make sure EventCollection doesn't modify input in-place
2 parents ed69d98 + 12f14c0 commit 6ba2651
Copy full SHA for 6ba2651

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
@@ -1456,12 +1456,15 @@ def __init__(self,
14561456
--------
14571457
.. plot:: gallery/lines_bars_and_markers/eventcollection_demo.py
14581458
"""
1459-
1459+
if positions is None:
1460+
raise ValueError('positions must be an array-like object')
1461+
# Force a copy of positions
1462+
positions = np.array(positions, copy=True)
14601463
segment = (lineoffset + linelength / 2.,
14611464
lineoffset - linelength / 2.)
1462-
if positions is None or len(positions) == 0:
1465+
if positions.size == 0:
14631466
segments = []
1464-
elif hasattr(positions, 'ndim') and positions.ndim > 1:
1467+
elif positions.ndim > 1:
14651468
raise ValueError('positions cannot be an array with more than '
14661469
'one dimension.')
14671470
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
@@ -711,3 +711,10 @@ def test_pathcollection_legend_elements():
711711
ax.add_artist(l)
712712

713713
fig.canvas.draw()
714+
715+
716+
def test_EventCollection_nosort():
717+
# Check that EventCollection doesn't modify input in place
718+
arr = np.array([3, 2, 1, 10])
719+
coll = EventCollection(arr)
720+
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.