8000 Update point add to handle multiple coordinates in data_indices by ClementCaporal · Pull Request #7536 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update point add to handle multiple coordinates in data_indices #7536

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 6 commits into from
Mar 14, 2025

Conversation

ClementCaporal
Copy link
Contributor

References and relevant issues

Closes #7507

Description

import napari

viewer = napari.Viewer()
point_layer = viewer.add_points()
point_layer.events.data.connect(lambda event: print('data_indices:', event.data_indices))
point_layer.add([[100, 100], [200, 200], [300, 300]]) # data_indices: (-3,-2,-1) (Before it was (-1,)

Two interrogations:

  • I couldn't check this final checklist: I feel the API changed, but I didn't find the appropriate docstring

    • If an API has been modified, I have added a .. versionadded:: or .. versionchanged::
      directive to the appropriate docstring (For more information see
      the Sphinx documentation).
  • Should event ActionType.ADDING have all the indices even if they haven't been added yet? here :

    data_indices=(-1,),

@github-actions github-actions bot added the tests Something related to our tests label Jan 18, 2025
Copy link
codecov bot commented Jan 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.84%. Comparing base (09f0e89) to head (eaa78ef).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7536      +/-   ##
==========================================
- Coverage   92.88%   92.84%   -0.05%     
==========================================
  Files         632      632              
  Lines       59258    59258              
==========================================
- Hits        55042    55018      -24     
- Misses       4216     4240      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor
@brisvag brisvag left a comment

Choose a reason for hi 8000 ding this comment

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

Hey @ClementCaporal, thanks for the PR! I would almost call this a bugfix, since the previous behaviour was just kinda wrong... But it's true that it changes the api, so maybe both bugfix and breaking change :P the release after 0.5.6 will probably be 0.6, so we could put this in there, if we're worried about breaking worklfows.

I have a suggestion: better to use np.arange for better performance, in case the user passes a large number of points (this returns an array instead of a tuple, but I think it's better here?)

In [11]: %timeit tuple(-i - 1 for i in reversed(range(len(coords))))
1.37 μs ± 11.5 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

In [12]: %timeit np.arange(-len(coords), 0)
875 ns ± 12.7 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

@brisvag brisvag added release:breaking change Breaking change requiring a deprecation notice bugfix PR with bugfix labels Jan 20, 2025
@jni
Copy link
Member
jni commented Jan 21, 2025

Should event ActionType.ADDING have all the indices even if they haven't been added yet? here :

That's a very good question! And I don't know the answer to it!!! 😬 I would say leave it alone — actually even -1 is misleading...

@jni jni added this to the 0.6.0 milestone Jan 21, 2025
@ClementCaporal
Copy link
Contributor Author
ClementCaporal commented Jan 21, 2025

Thank you for your reviews @brisvag @jni

  • I reversed to (-1,) for the adding event
  • I used np.arange to create the data_indices but I put it back in a tuple so it matches the typing of the other events (for example here : ) If this should not be a tuple, maybe another PR changing the typing of all events might be necessary?
    kwargs['data_indices'] = tuple(i for i in range(len(data)))

@jni jni added the api PR/Issue involving API design changes label Mar 14, 2025
@jni jni merged commit e2ca4c2 into napari:main Mar 14, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api PR/Issue involving API design changes bugfix PR with bugfix release:breaking change Breaking change requiring a deprecation notice tests Something related to our tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Point Layer add event does not contain all data_indices
3755
4 participants
0