Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow update of zcollection global and variable metadata #20

Open
robin-cls opened this issue Jan 31, 2025 · 0 comments
Open

Allow update of zcollection global and variable metadata #20

robin-cls opened this issue Jan 31, 2025 · 0 comments

Comments

@robin-cls
Copy link

robin-cls commented Jan 31, 2025

Hello, I have a suggestion for improving a collection management. For now, it seems impossible to update global and variable metadata once a collection is created. It would be a great addition if we could update or edit the attributes of a variable or the global attributes

Code for collection creation
from __future__ import annotations

from typing import Iterator
import datetime
import pprint
import dask_jobqueue
import os
import dask.distributed
import fsspec
import numpy
import dask

import zcollection
import zcollection.tests.data

cluster = dask.distributed.LocalCluster(processes=False)
client = dask.distributed.Client(cluster)

zds = next(zcollection.tests.data.create_test_dataset_with_fillvalue())

fs = fsspec.filesystem('memory')

partition_handler = zcollection.partitioning.Date(('time', ), resolution='M')
collection: zcollection.Collection = zcollection.create_collection(
    'time', zds, partition_handler, '/my_collection', filesystem=fs)

collection.insert(zds)

Below is a snippet that I think can help illustrate what we want to achieve

print(f'Global attributes before update: {collection.load().attrs}')
print(f'Variable attribute before update: {collection.load()["var1"].attrs}')
>> Global attributes before update: (Attribute('attr', 1),)
>> Variable attribute before update: (Attribute('attr', 1),)

# These would be the new methods. Eventually they could be called from the
# collection instance
update_global_attributes(collection, [Attribute('attr', 2), Attribute('foo', 'bar')])
update_variable_attributes(collection, [Attribute('attr', 3), Attribute('fooz', 'baz')])

print(f'Global attributes after update: {collection.load().attrs}')
print(f'Variable attribute after update: {collection.load()["var1"].attrs}')
>> Global attributes after update: (Attribute('attr', 2), Attribute('foo', 'bar'))
>> Variable attribute after update: (Attribute('attr', 3), Attribute('fooz', 'baz'))
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

No branches or pull requests

1 participant