Skip to content

Conversation

@d33bs
Copy link
Member

@d33bs d33bs commented Aug 12, 2025

Description

This PR adds the option to export data to anndata formats h5ad and zarr.

In order to reach this I felt that we should abstract the initial design of CytoTable to enable these and other export formats in the near future. To this effect, I changed _to_parquet to be _run_export_workflow (which is more true to what it does anyhow).

Please note: the anndata project is only compatible with Python <=3.11 and as a result shifts how implementation was performed.

Closes #346

What is the nature of your change?

  • Bug fix (fixes an issue).
  • Enhancement (adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • This change requires a documentation update.

Checklist

Please ensure that all boxes are checked before indicating that a pull request is ready for review.

  • I have read the CONTRIBUTING.md guidelines.
  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • New and existing unit tests pass locally with my changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have deleted all non-relevant text in this pull request template.

@d33bs d33bs changed the title Add anndata destination options (.h5ad, .zarr) Add anndata export options (.h5ad, .zarr) Aug 12, 2025
@d33bs d33bs marked this pull request as ready for review August 13, 2025 15:46
@d33bs d33bs requested a review from gwaybio August 13, 2025 15:47
Copy link
Member

@gwaybio gwaybio left a comment

Choose a reason for hiding this comment

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

Amazing to see this functionality! Once anndata is added, it is worth a minor release IMO 🎉

d33bs and others added 7 commits August 13, 2025 11:21
Co-Authored-By: Gregory Way <gregory.way@gmail.com>
Co-Authored-By: Gregory Way <gregory.way@gmail.com>
Co-Authored-By: Gregory Way <gregory.way@gmail.com>
Co-Authored-By: Gregory Way <gregory.way@gmail.com>
Co-Authored-By: Gregory Way <gregory.way@gmail.com>
@d33bs
Copy link
Member Author

d33bs commented Aug 13, 2025

Thanks @gwaybio ! Merging this in after making changes.

@d33bs d33bs merged commit 2500c61 into cytomining:main Aug 13, 2025
12 checks passed
@d33bs d33bs deleted the anndata-output branch August 13, 2025 20:43
{ version = "<0.12.2", python = "<3.11" },
{ version = ">=0.12.2", python = ">=3.11" },
]
# zarr is required by anndata <0.12.2
Copy link

@flying-sheep flying-sheep Aug 14, 2025

Choose a reason for hiding this comment

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

Zarr is a required dependency in anndata >=0.12.0, not <!

Copy link
Member Author

@d33bs d33bs Aug 14, 2025

Choose a reason for hiding this comment

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

Thanks for checking in on this @flying-sheep and sorry again about the version issue confusion on my part! I should have been more explicit with this particular comment; I found that I needed to manually add zarr for anndata <0.12.2 with Python 3.10 and below.

Here's an example reproducing the error I saw:

example.py

import anndata as ad
import pandas as pd

print(ad.__version__)

adata = ad.AnnData(X=pd.DataFrame({"example":[1,2,3]}))

adata.write_zarr("example.zarr")

Executed with uvx using only pandas and anndata through Python 3.10:

uvx -p 3.10 --with anndata,pandas python example.py

Yields an error: ImportError: zarr is not installed.

From this PR's standpoint I sought mostly to find a simple resolution for the many different possible versions which could be installed. Do you feel we should raise an issue about this within anndata (happy to do so)? I felt it might be due to what might have previously been treated as an optional or extra installation within the package (and perhaps not an actual error / fault of the project).

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a minor clarification on the zarr dependency comment in #352 - thanks again for your comment!

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.

Add anndata export capabilities

3 participants