Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixed eventplot issues #22286

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
Apr 14, 2023
Merged

Fixed eventplot issues #22286

merged 1 commit into from
Apr 14, 2023

Conversation

oscargus
Copy link
Member

PR Summary

This is not finalized, but more a base for discussion. (Tests will be added once the final solution is decided.)

Closes #7560

There are two issues that are considered here:

  1. There seems to be a bit of copy-and-paste errors (the original issue in Edge cases in eventplot are likely broken #7560). Here, the proposed solution is to error on empty iterables. This changes the earlier solution, but only for a few of the parameters (although the error message will change for all).
  2. There is a bit of code for dealing with the positions not being an iterable. However, although this is put within a list, it will break later as the actual position is still not an iterable. Here, it is suggested to support that type of call (eventplot(1)), but one can also consider raising an error with an appropriate error message already there.

Finally, an if-statement that I cannot see can even be triggered is removed.

(Issue 2 and the removal came from trying to test these lines, which lead me to find #7560 and the earlier attempts to fix it.)

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@oscargus
Copy link
Member Author

Now I remember the issue with:

        if not np.iterable(positions):
            positions = [positions]

This deals with e.g. scalars, but will break later on in EventCollection with:

        if np.ndim(positions) != 1:
           raise ValueError('positions must be one-dimensional')

Are there any inputs that are not np.iterable, but still will give np.dim() == 1? If not, we are just delaying the error to happen when positions is a scalar (not an array).

@@ -1313,9 +1313,6 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
else:
positions = [np.asanyarray(positions)]

if len(positions) == 0:
Copy link
Member Author

Choose a reason for hiding this comment

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

Because of the code above, this cannot happen.

lineoffsets = [None]
raise ValueError('linewidths cannot be empty')
if len(alpha) == 0:
raise ValueError('alpha cannot be empty')
Copy link
Member Author

Choose a reason for hiding this comment

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

This is added compared to the discussion we had. For similar behavior and it will still break with unequal sizes below.

An option is to skip all these len() == 0 checks, except for colors, and rely on the unequal size below. Fewer checks, but slightly worse error message.

@oscargus oscargus marked this pull request as ready for review April 13, 2023 20:47
@tacaswell tacaswell added this to the v3.8.0 milestone Apr 14, 2023
@timhoffm timhoffm merged commit 3f4d4c1 into matplotlib:main Apr 14, 2023
@oscargus oscargus deleted the eventplotfixes branch April 14, 2023 23:51
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.

Edge cases in eventplot are likely broken
3 participants