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

Fix the update method and fix the dask lock (need test) #119

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='TensorDB',
version='0.30.3',
version='0.30.4',
description='Database based in a file system storage combined with Xarray and Zarr',
author='Joseph Nowak',
author_email='[email protected]',
Expand Down
1 change: 0 additions & 1 deletion tensordb/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@ def rolling_overlap(
data = new_data.data

def _apply_on_valid(x):
x = x.copy()
bitmask = ~np.isnan(x)
filter_x = x[bitmask]

Expand Down
8 changes: 8 additions & 0 deletions tensordb/storages/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os.path
from typing import Type

import dask.distributed


class BaseLock(abc.ABC):
def __enter__(self):
Expand Down Expand Up @@ -30,3 +32,9 @@ def __init__(self, prefix: str, lock: Type[BaseLock] = None):
def __getitem__(self, path):
path = os.path.join(self.prefix, path)
return self.lock(path)


class DaskLock(PrefixLock):
def __getitem__(self, path):
path = os.path.join(self.prefix, path)
return dask.distributed.Lock(path)
7 changes: 5 additions & 2 deletions tensordb/storages/zarr_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ def update(
compute=compute,
synchronizer=self.synchronizer,
region=regions,
# This option is save based on this https://github.com/pydata/xarray/issues/9072
safe_chunks=False
)
return delayed_write

Expand Down Expand Up @@ -473,13 +475,14 @@ def read(self) -> Union[xr.DataArray, xr.Dataset]:
with some names or a name
"""
try:
arr = xr.open_zarr(
dataset = xr.open_zarr(
self.base_map,
consolidated=True,
synchronizer=None if self.synchronize_only_write else self.synchronizer,
group=self.group,
)
return arr[self.data_names]
dataset = dataset[self.data_names]
return dataset
except KeyError as e:
raise KeyError(
f"The data_names {self.data_names} does not exist on the tensor "
Expand Down
Loading