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

Make sure EventCollection doesn't modify input in-place #14488

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 3 commits into from
Jun 18, 2019

Conversation

dstansby
Copy link
Member

@dstansby dstansby commented Jun 7, 2019

Fixes #14487. Not entirely sure if casting any input to an array is correct, but will see if the tests all pass.

@dstansby dstansby changed the title Make sure EventCollection doesn't modify in put inplace Make sure EventCollection doesn't modify input in-place Jun 7, 2019
@@ -1462,7 +1462,7 @@ def __init__(self,

.. plot:: gallery/lines_bars_and_markers/eventcollection_demo.py
"""

positions = np.array(positions, copy=True)
segment = (lineoffset + linelength / 2.,
lineoffset - linelength / 2.)
if positions is None or len(positions) == 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

At least this line suggests it was intended that positions could be None, but this PR changes the handling of None.

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh, you're right, even if there is a comment above (https://github.com/matplotlib/matplotlib/pull/14488/files#diff-506c6bd01694bddbd8999f2c6e920705R1408) that implies positions can't be None. I'll fix it to keep the current behaviour with None though (and add a smoke test for positions=None)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really know if it can be None or not, could probably use some cleanup :p

Copy link
Member Author

Choose a reason for hiding this comment

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

Since passing positions=None would fail later on in some cases on positions.sort(), I've explicitly disallowed None input.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would previously not fail because the sort() is in another else clause; indeed gca().add_collection(EventCollection(None)) works.
On the other hand there's basically not benefit to supporting None as input (in particular eventplot(None) already doesn't work) so I'm fine with dropping that, won't even insist on an api changes note... :)

@tacaswell tacaswell added this to the v3.1.2 milestone Jun 10, 2019

if positions is None:
raise ValueError('positions must be an array-like object')
positions = np.array(positions, copy=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically np.array already copies by default (and there's likely a ton of places in the codebase which rely on that), so just a comment # force a copy is enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think having copy=True makes it much more clear what is going on, but happy to add a comment too

@anntzer
Copy link
Contributor

anntzer commented Jun 18, 2019

anyone can merge post ci

@timhoffm timhoffm merged commit 6ba2651 into matplotlib:master Jun 18, 2019
@dstansby dstansby deleted the event-coll-inplac branch June 18, 2019 21:26
@QuLogic
Copy link
Member

QuLogic commented Jul 17, 2019

@meeseeksdev backport to v3.1.x

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jul 17, 2019
QuLogic added a commit that referenced this pull request Jul 17, 2019
…488-on-v3.1.x

Backport PR #14488 on branch v3.1.x (Make sure EventCollection doesn't modify input in-place)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eventplot sorts np.array positions, but not list positions
5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.