Skip to content

Getting started converter() issue - ValueError issues #35

Description

@NG-sama

ValueError Issue occurs during conversion of .h5ad file to .slaf. Issue identified due to use of hardcoded "data" value as input for X_Group.

Issue output as follows

File ".venv/lib/python3.13/site-packages/slaf/data/converter.py", line 2361, in _validate_optimized_dtypes
    if "data" in X_group:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Solution:

Within converter.py perform the following changes (commented lines are changes):

            # Check the original data type from the h5ad file
            X_group = reader.file["X"]
            data = X_group.get("data") if hasattr(X_group, "get") else None

            # if "data" in X_group:
            if data is not None:
                # Sample some original data
                # data = X_group["data"]
                sample_size = min(10000, len(data))
                # Use sequential sampling instead of random to avoid indexing issues
                sample_data = data[:sample_size]

Code as follows:

import marimo as mo

from slaf import SLAFArray
from slaf.integrations import scanpy as slaf_scanpy
from slaf.integrations.anndata import read_slaf
import scanpy as sc
from slaf.data.converter import SLAFConverter

dtest = sc.datasets.pbmc3k_processed()
# Convert to SLAF format
converter = SLAFConverter()
slaf_path = "pbmc3k.slaf"
converter.convert("/filepath/pbmc3k_processed.h5ad",slaf_path)

print(f"✅ Converted to SLAF format: {slaf_path}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions