Reduce numpy array traceback print#2910
Reduce numpy array traceback print#2910sofroniewn merged 4 commits intonapari:masterfrom JoOkuma:array-traceback
Conversation
tlambert03
left a comment
There was a problem hiding this comment.
works for me, thanks!
One possible elaboration would be to accept a parameter to format_exc_info that controls this behavior... then
- add a checkbox to the
QtPluginErrReportthat lets the user control this. - pass the value of the checkbox to
format_exceptionshere - pass that value through to
format_exc_infohere
| info: ExcInfo, as_html: bool, color='Neutral' | ||
| ) -> str: | ||
| # avoids printing the array data | ||
| np.set_string_function( |
There was a problem hiding this comment.
two thoughts:
a) is there a way to get the current string_function? (so that we can restore it in case a user has already set it?)
b) we probably want to be extra careful not to set this on someone and have it be permanent... so probably best to put everything between this line and the set_string_function(None) line in a try/finally clause to make sure that we set it back to whatever it was before
There was a problem hiding this comment.
I could not find a way to get it back, I think it is not exposed to the NumPy Python API :(
There was a problem hiding this comment.
yeah, bummer... some discussion here: numpy/numpy#11266
Codecov Report
@@ Coverage Diff @@
## master #2910 +/- ##
==========================================
- Coverage 82.97% 82.96% -0.01%
==========================================
Files 500 500
Lines 41998 42020 +22
==========================================
+ Hits 34846 34863 +17
- Misses 7152 7157 +5
Continue to review full report at Codecov.
|
Thanks for the suggestion. I will do that. |
|
Unfortunately, the state of the check box inside the |
|
well, it could be added as a persistent setting... but it's fine if you want to leave that for (possibly) the future. if other @napari/core-devs are fine with this display mode (without having an option to change it) then it's fine with me |
|
Nice work! I havn't tried yet, but sounds great.
Yeah, I might just drop the check box inside the QtPluginErrReport if not stored and just add the persistent setting. Shouldn't be too hard to add and might as well do now. @ppwadhwa can advise if you run into problems. I'd probably put in the Application panel |
|
It feels kinda weird to have to go into the preferences window to modify the appearance of a traceback in a different dialog don't you think? If it were in the plugin error dialog, one could check/uncheck it and immediately change the display (if they wanted to see the full array for some reason). I'm not sure that every persistent setting necessarily needs to go into the main preferences window... and we could run into bloat like that I think I'd probably even prefer the checkbox in the plugin error dialog without persistence over the standard preferences window with persistence... it's not a big deal to have to check it each time whenever you want to see the full array. |
Does this only effect tracebacks in the error dialog? Don't we also have a way to see tracebacks in the GUI in the bottom right and would this setting not effect them too?
I don't know, I think need to group and organize the settings to prevent bloat - so maybe this doesn't go in the main application setting, but some additional section, but I think i'd find it odd if i was trying to find a persistent setting and it wasn't in somewhere in main preferences window
Yeah that's fair. My feelings about this are pretty weak right now, so @tlambert03 if you think this is good to go in now as is then I'm happy with it too. We can always revisit some of this stuff in the future. Let us know though if you want to see additional changes before merge, otherwise I'll put this in the awaiting merge section |
|
we chatted about this and are happy with the original functionality as you had it (i.e. no option to change the display, just always showing array shape and dtype). sorry for the runaround. am I correct in understanding that currently the checkbox effectively does nothing? I'm fine with either of those options and leave it to you to decide. let us know when it's ready and we can merge. thanks again! |
|
I reverted the changes so we don't have the checkbox anymore. I added some additional comments and extended the functionality to the traceback when Thanks for the input. |
tlambert03
left a comment
There was a problem hiding this comment.
perfect. thanks again!
# References and relevant issues * Closes #6752 * Reference https://numpy.org/devdocs/numpy_2_0_migration_guide.html#ruff-plugin * Previous related PR #2910 # Description This PR: 1. Adds a ruff linting rule to check compatibility with numpy v2.0, and 2. Updates existing napari code to ensure compatibility with numpy v2.0 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Description
This PR changes the print behavior for NumPy arrays during traceback within napari.
Traceback before
Traceback after
Type of change
References
The chosen string formatting imitates the zarr string representation.
The numpy function used is documented here. Unfortunately, it does not provide a context manager.
An alternative would be set_printoptions but the formatting changes are more limited.
How has this been tested?
Final checklist:
trans.to make them localizable.For more information see our translations guide.
Note
I left some checkboxes unchecked because I'm not sure if they are relevant.
Additional suggestions are welcome.