zarr-python icon indicating copy to clipboard operation
zarr-python copied to clipboard

Add a close method to the DirectoryStore and N5Store

Open hmaarrfk opened this issue 5 years ago • 3 comments

The ZipStore contains a close method that ensures that the file is flushed on the OS, and ready for the next line of code to use.

It wouild be nice to have noop methods for the DirectoryStore (and N5Store) to ensure that we don't have to use the following code downstream

if hasattr(store, 'close'): 
    store.close()

Minimal, reproducible code sample, a copy-pastable example if possible

import zarr
dstore = zarr.DirectoryStore('test.dir')
dstore.close()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-a0f668fd8b50> in <module>
----> 1 dstore.close()

AttributeError: 'DirectoryStore' object has no attribute 'close'

import zarr
zstore = zarr.ZipStore('test.zip')
zstore.close()
# All good

Version and installation information

Please provide the following:

  • Value of zarr.__version__: 2.4.1.dev15+dirty

  • Value of numcodecs.__version__: 0.6.4

  • Version of Python interpreter: 3.8.5

  • Operating system (Linux/Windows/Mac) Linux

  • How Zarr was installed (e.g., "using pip into virtual environment", or "using conda"): conda-forge

hmaarrfk avatar Aug 31 '20 20:08 hmaarrfk

Usage example: https://github.com/pydata/xarray/pull/4395

hmaarrfk avatar Aug 31 '20 21:08 hmaarrfk

cc: @Carreau

joshmoore avatar Sep 09 '20 19:09 joshmoore

Opened #600 to track other advantages of having a base store that implements boilerplate methods like close().

Carreau avatar Sep 09 '20 20:09 Carreau

@joshmoore @MSanKeys963 I'm an Outreach candidate and would like to work on this.

ManMaich0 avatar Oct 25 '22 15:10 ManMaich0

I think this issue can be closed. It seems that since #600 was closed, this is no longer an issue with at least the latest version of zarr.

In [1]: import zarr
   ...: dstore = zarr.DirectoryStore('test.dir')
   ...: dstore.close()

In [2]: zarr.__version__
'2.13.3'

hmaarrfk avatar Oct 26 '22 12:10 hmaarrfk

Thanks Mark! 🙏

Glad to hear things are working now 😄

jakirkham avatar Oct 26 '22 15:10 jakirkham