Skip to content

Issue with Xenium data and with PyQT#397

Open
plooney wants to merge 3 commits into
scverse:mainfrom
plooney:main
Open

Issue with Xenium data and with PyQT#397
plooney wants to merge 3 commits into
scverse:mainfrom
plooney:main

Conversation

@plooney
Copy link
Copy Markdown

@plooney plooney commented May 20, 2026

Hello,

I have had a couple of issues with using napari-spatialdata with Xenium and PySide6.

The issue with Xenium data was as below

import os
import sys

os.environ.setdefault("PYQTGRAPH_QT_LIB", "PySide6")
try:
    from pyqtgraph.Qt import QtCore
    if not hasattr(QtCore, "pyqtSignal"):
        QtCore.pyqtSignal = QtCore.Signal
    if not hasattr(QtCore, "pyqtSlot"):
        QtCore.pyqtSlot = QtCore.Slot
except ImportError:
    pass

import numpy as np
import pandas as pd
import geopandas as GeoDataFrame
from shapely.geometry import Polygon
from spatialdata import SpatialData
from spatialdata.models import ShapesModel
from spatialdata.transformations import Identity
from napari_spatialdata import Interactive
import napari

def reproduce_bug():
    # 1. Create a synthetic polygon (a simple square)
    poly = Polygon([(0, 0), (0, 10), (10, 10), (10, 0)])
    
    # 2. Create a GeoDataFrame with a STRING index (simulating Xenium IDs like 'aaaaapcc-1')
    gdf = GeoDataFrame.GeoDataFrame(
        {"geometry": [poly]}, 
        index=["aaaaapcc-1"]
    )
    
    # 3. Wrap it in a SpatialData object
    shapes = ShapesModel.parse(gdf, transformations={"global": Identity()})
    sdata = SpatialData(shapes={"cell_boundaries": shapes})
    
    print("Synthetic SpatialData object created with string index.")
    print(f"Index value: {gdf.index[0]}")
    print("\nAttempting to load into napari-spatialdata...")
    print("EXPECTED BEHAVIOR: The SdataWidget should show 'cell_boundaries'.")
    print("ACTUAL BUG: Double-clicking 'cell_boundaries' or auto-loading it will raise:")
    print("ValueError: invalid literal for int() with base 10: 'aaaaapcc-1'")
    
    # 4. Launch the viewer
    viewer = napari.Viewer()
    interactive = Interactive(sdata, headless=True)
    
    print("\nViewer launched. To trigger the bug:")
    print("1. Locate the 'SpatialData' dock widget on the left.")
    print("2. Double-click 'cell_boundaries'.")
    
    napari.run()

if __name__ == "__main__":
    reproduce_bug()

There was also an import issue with PyQT that I had to work around. Both of these are in this pull request.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.84%. Comparing base (69105e0) to head (ad45d98).
⚠️ Report is 70 commits behind head on main.

Files with missing lines Patch % Lines
src/napari_spatialdata/utils/_viewer_utils.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #397      +/-   ##
==========================================
+ Coverage   63.08%   70.84%   +7.75%     
==========================================
  Files          19       19              
  Lines        2636     3399     +763     
==========================================
+ Hits         1663     2408     +745     
- Misses        973      991      +18     

☔ 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.

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.

1 participant