Skip to content
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

Enable xarray v2024.10.0+ #304

Open
gselzer opened this issue Oct 29, 2024 · 2 comments
Open

Enable xarray v2024.10.0+ #304

gselzer opened this issue Oct 29, 2024 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@gselzer
Copy link
Collaborator

gselzer commented Oct 29, 2024

For some reason, xarray v2024.10.0 and above breaks CI on Ubuntu, with Python 3.12. At the end of this issue is a snippet of the CI failure, saved because the logs will delete later on. I placed an exclusive upper bound on this version in #303, even though I cannot reproduce the error on an available WSL instance.

This is the commit in xarray that made the breaking change.

@elevans @ctrueden thoughts on how to proceed here? Does this failure affect PyImageJ in any way?

-------------------------------------
| Testing ImageJ2 + original ImageJ |
-------------------------------------
============================= test session starts ==============================
platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0
PyQt5 5.15.11 -- Qt runtime 5.15.15 -- Qt compiled 5.15.14
rootdir: /home/runner/work/napari-imagej/napari-imagej
configfile: pyproject.toml
plugins: napari-plugin-engine-0.2.0, qt-4.4.0, cov-6.0.0, npe2-0.7.7, napari-0.5.4, env-1.1.5
collected 167 items

tests/test_java.py Oct 29, 2024 9:56:42 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.

======= BEGIN JAVA VERSIONS =======
io.scif:scifio 0.45.0
net.imagej:ij 1.54f (no minimum)
net.imagej:imagej 2.15.0 (no minimum)
net.imagej:imagej-common 2.0.4
net.imagej:imagej-legacy 1.2.1
net.imagej:imagej-ops 2.0.0
net.imglib2:imglib2-imglyb 1.1.0
net.imglib2:imglib2-unsafe 1.0.0
org.scijava:scijava-common 2.97.0
org.scijava:scijava-search 2.0.4
sc.fiji:fiji NOT PRESENT
======== END JAVA VERSIONS ========
...
tests/test_scripting.py .
tests/test_settings.py ......
tests/types/test_converters.py .....................................
tests/types/test_enums.py .
tests/types/test_trackmate.py s
tests/types/test_type_conversions.py ......
tests/types/test_widget_mappings.py ................
tests/utilities/test_module_utils.py ..................................
tests/utilities/test_progress.py 
Frangi Vesselness: 100%|██████████| 3/3 [00:00<00:00, 23921.89it/s]
....
tests/widgets/test_info_bar.py .
tests/widgets/test_menu.py ..s.ss...F...
tests/widgets/test_napari_imagej.py .............
tests/widgets/test_parameter_widgets.py ...................
tests/widgets/test_result_runner.py ...
tests/widgets/test_result_tree.py .......
tests/widgets/test_searchbar.py ..

=================================== FAILURES ===================================
_________________________ test_modification_in_imagej __________________________

asserter = <function asserter.<locals>.assertFunc at 0x7f9d28dcdf80>
qtbot = <pytestqt.qtbot.QtBot object at 0x7f9d40f0c920>
ij = <java object 'net.imagej.ImageJ'>
gui_widget = <napari_imagej.widgets.menu.NapariImageJMenu object at 0x7f9dc8927140>

    def test_modification_in_imagej(asserter, qtbot, ij, gui_widget: NapariImageJMenu):
        if settings.headless():
            pytest.skip("Only applies when not running headlessly")
        if not settings.include_imagej_legacy:
            pytest.skip("Tests legacy behavior")
    
        to_button: ToIJButton = gui_widget.to_ij
        from_button: FromIJButton = gui_widget.from_ij
    
        # Show the button
        qtbot.mouseClick(gui_widget.gui_button, Qt.LeftButton, delay=1)
    
        # Add some data to the viewer
        sample_data = numpy.ones((100, 100, 3), dtype=numpy.uint8)
        image: Image = Image(data=sample_data, name="test_to")
        current_viewer().add_layer(image)
    
        # Press the button, handle the Dialog
        qtbot.mouseClick(to_button, Qt.LeftButton, delay=1)
    
        # Assert that the data is in the legacy UI
        asserter(lambda: ij.WindowManager.getCurrentImage() is not None)
        imp = ij.WindowManager.getCurrentImage()
        assert imp.getTitle() == "test_to"
        # Edit the data
        imp.getProcessor().invert()
        imp.updateAndDraw()
    
        # Press the button, handle the Dialog
        qtbot.mouseClick(from_button, Qt.LeftButton, delay=1)
    
        # Assert the returned data is inverted
        asserter(lambda: "test_to [1]" in current_viewer().layers)
        modified_layer = current_viewer().layers["test_to [1]"].data
>       assert numpy.all(modified_layer[0, :, :] == 254)

tests/widgets/test_menu.py:470: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/xarray/core/_typed_ops.py:457: in __eq__
    return self._binary_op(other, nputils.array_eq)
/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/xarray/core/dataarray.py:4786: in _binary_op
    name = result_name([self, other])
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

objects = [<xarray.DataArray array([[[254, 254, 254],
        [254, 254, 254],
        [254, 254, 254],
        ...,
        [25...   (row) float64 800B 0.0 1.0 2.0 3.0 4.0 ... 95.0 96.0 97.0 98.0 99.0
  * col      (col) float64 24B 0.0 1.0 2.0, 254]

    def result_name(objects: Iterable[Any]) -> Any:
        # use the same naming heuristics as pandas:
        # https://github.com/blaze/blaze/issues/458#issuecomment-51936356
>       names = {getattr(obj, "name", _DEFAULT_NAME) for obj in objects}
E       TypeError: unhashable type: 'numpy.ndarray'

/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/xarray/core/utils.py:1206: TypeError
=============================== warnings summary ===============================
../../../../../opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/copy.py:151
  /opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/copy.py:151: DeprecationWarning: Pickle, copy, and deepcopy support will be removed from itertools in Python 3.14.
    rv = reductor(4)

../../../../../opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/copy.py:261
  /opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/copy.py:261: DeprecationWarning: Pickle, copy, and deepcopy support will be removed from itertools in Python 3.14.
    y.__setstate__(state)

src/napari_imagej/types/converters/trackmate.py:26
  /home/runner/work/napari-imagej/napari-imagej/src/napari_imagej/types/converters/trackmate.py:26: SyntaxWarning: invalid escape sequence '\d'
    if match("TrackMate-\d.*\.jar", fname):  # noqa

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/widgets/test_menu.py::test_modification_in_imagej - TypeError: unhashable type: 'numpy.ndarray'
======= 1 failed, 162 passed, 4 skipped, 3 warnings in 64.71s (0:01:04) ========
@gselzer gselzer added the bug Something isn't working label Oct 29, 2024
@gselzer gselzer added this to the unscheduled milestone Oct 29, 2024
@elevans
Copy link
Member

elevans commented Dec 17, 2024

Can you reproduce this bug locally or just in CI? I'll see if I can replicate this. I had to make this change to pyimagej due to xarray API deprecation. I'm wondering if something similar is happening here.

@gselzer
Copy link
Collaborator Author

gselzer commented Dec 20, 2024

Nope, also happens locally (Windows 10, Powershell). Reproducible using:

  1. On the main branch of napari-imagej, run mamba env create -f dev-envrionment.yml
  2. mamba install -c conda-forge xarray==2024.11.0
  3. mamba run pytest

I receive an error equivalent to the error on CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants