Skip to content

Conversation

LucaMarconato
Copy link
Member

zarr-python v3 removed the context manager functionalities from zarr.open (zarr-developers/zarr-python#2619). This small PR adds a workaround for that.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses the removal of context manager functionality from zarr.open in zarr-python v3 by implementing a workaround that provides the missing context manager behavior.

  • Implements a custom zarr_open context manager function to replace direct zarr.open usage
  • Updates all instances of zarr.open context manager usage to use the new workaround function
  • Ensures proper cleanup of zarr stores when exiting the context

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/spatialdata_io/_utils.py Adds zarr_open context manager workaround function with proper store cleanup
src/spatialdata_io/readers/xenium.py Updates zarr.open usage to use the new zarr_open context manager

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

try:
yield f
finally:
f.store.close()
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

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

Calling f.store.close() may fail if the store doesn't have a close() method or if f.store is None. Consider adding a check to ensure the store exists and has a close method before calling it, or wrap in a try-except block to handle potential AttributeError.

Suggested change
f.store.close()
if f.store is not None and hasattr(f.store, "close"):
f.store.close()

Copilot uses AI. Check for mistakes.

@LucaMarconato LucaMarconato merged commit 638677a into main Oct 4, 2025
5 checks passed
@LucaMarconato LucaMarconato deleted the zarrv3-context-manager branch October 4, 2025 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant