Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Move MemoryStore to a persistent store (e.g. LocalStore)#2985

Answeredbyd-v-b
kevinli1993 asked this question inQ&A
Discussion options

Hi, once I put data inside a group on a MemoryStore, how do I copy the group over to a persistent store?

root = zarr.create_group(store={})# put data in root# Now I want to move this to a persistent storestore = LocalStore("....")store.MAGIC_COPY_COMMAND(from=root)

I see there is zarr.copy() and zarr.copy_group(), but they are not implemented; reading the linked issue, it is also unclear whether they would be removed.

Curious if the use-case above would be supported? Thanks.

You must be logged in to vote
Answered by d-v-bApr 15, 2025

hi@kevinli1993 this is a great question and we should absolutely support this with a stand-alone convenience function. Until we get around to writing such a convenience function ,here's a script that illustrates how you can do this today:

# /// script# requires-python = ">=3.11"# dependencies = [#     "zarr>3",# ]# ///importzarrfromzarr.storageimportMemoryStorefromzarr.core.bufferimportdefault_buffer_prototypeimportasynciomem_a= {}mem_b= {}store_a=MemoryStore(mem_a)store_b=MemoryStore(mem_b)# create an array and fill it with valuesarray=zarr.create_array(store_a,name='foo',shape=(10,),dtype='float32')array[:]=1# define an async function that lis…

Replies: 1 comment 2 replies

Comment options

hi@kevinli1993 this is a great question and we should absolutely support this with a stand-alone convenience function. Until we get around to writing such a convenience function ,here's a script that illustrates how you can do this today:

# /// script# requires-python = ">=3.11"# dependencies = [#     "zarr>3",# ]# ///importzarrfromzarr.storageimportMemoryStorefromzarr.core.bufferimportdefault_buffer_prototypeimportasynciomem_a= {}mem_b= {}store_a=MemoryStore(mem_a)store_b=MemoryStore(mem_b)# create an array and fill it with valuesarray=zarr.create_array(store_a,name='foo',shape=(10,),dtype='float32')array[:]=1# define an async function that lists the contents of the source store and copies each key, value pair to the dest storeasyncdefcopy_store(store_a,store_b):asyncforxinstore_a.list():awaitstore_b.set(x,awaitstore_a.get(x,prototype=default_buffer_prototype()))print(f'setting{x} ')returnNone# run that async functionasyncio.run(copy_store(store_a,store_b))# check that the two dictionaries are identical, i.e. everything from mem_a is in mem_bassertmem_a==mem_b
You must be logged in to vote
2 replies
@jhamman
Comment options

Noting that we have an open issue forzarr.copy_store:#2407

@kevinli1993
Comment options

Thanks@d-v-b for the example snippet -- it works well and also taught me a bit about.set() and.get() methods in the process. Also thanks@jhamman for the reference.

Answer selected bykevinli1993
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
3 participants
@kevinli1993@jhamman@d-v-b

[8]ページ先頭

©2009-2025 Movatter.jp