Skip to content

ds.to_zarr error on creation #1954

@kaipak

Description

@kaipak

Creating just a sample dataset:

data    = xr.DataArray(np.random.randn(2, 3), coords={'x': ['a', 'b']}, dims=('x', 'y'))
ds_test = xr.Dataset({'foo': data, 'bar': ('x', [1, 2]), 'baz': np.pi})
print(ds_test)
ds_test.to_zarr(store='foo.zarr', mode='w')

Writing this locally. This generates a .zgroup and .zattrs file, but then fails out with, AttributeError: 'Attributes' object has no attribute 'put'. Tried on a couple machines and I get the same error each time.

Run on:

MacOS 10.13.3
CentOS Linux release 7.4.1708 (Core)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-38-d75fe1649815> in <module>()
     11 ).chunk({'y': 50, 'x': 40})
     12 
---> 13 ds.to_zarr(store='/home/kyp/foo.zarr', mode='w')

~/.conda/envs/kai/lib/python3.6/site-packages/xarray/core/dataset.py in to_zarr(self, store, mode, synchronizer, group, encoding)
   1165         from ..backends.api import to_zarr
   1166         return to_zarr(self, store=store, mode=mode, synchronizer=synchronizer,
-> 1167                        group=group, encoding=encoding)
   1168 
   1169     def __unicode__(self):

~/.conda/envs/kai/lib/python3.6/site-packages/xarray/backends/api.py in to_zarr(dataset, store, mode, synchronizer, group, encoding)
    752     # I think zarr stores should always be sync'd immediately
    753     # TODO: figure out how to properly handle unlimited_dims
--> 754     dataset.dump_to_store(store, sync=True, encoding=encoding)
    755     return store

~/.conda/envs/kai/lib/python3.6/site-packages/xarray/core/dataset.py in dump_to_store(self, store, encoder, sync, encoding, unlimited_dims)
   1068 
   1069         store.store(variables, attrs, check_encoding,
-> 1070                     unlimited_dims=unlimited_dims)
   1071         if sync:
   1072             store.sync()

~/.conda/envs/kai/lib/python3.6/site-packages/xarray/backends/zarr.py in store(self, variables, attributes, *args, **kwargs)
    378     def store(self, variables, attributes, *args, **kwargs):
    379         AbstractWritableDataStore.store(self, variables, attributes,
--> 380                                         *args, **kwargs)
    381 
    382 

~/.conda/envs/kai/lib/python3.6/site-packages/xarray/backends/common.py in store(self, variables, attributes, check_encoding_set, unlimited_dims)
    275         variables, attributes = self.encode(variables, attributes)
    276 
--> 277         self.set_attributes(attributes)
    278         self.set_dimensions(variables, unlimited_dims=unlimited_dims)
    279         self.set_variables(variables, check_encoding_set,

~/.conda/envs/kai/lib/python3.6/site-packages/xarray/backends/zarr.py in set_attributes(self, attributes)
    341 
    342     def set_attributes(self, attributes):
--> 343         self.ds.attrs.put(attributes)
    344 
    345     def encode_variable(self, variable):

AttributeError: 'Attributes' object has no attribute 'put'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions