Skip to content

Commit

Permalink
Merge pull request #122 from josephnowak/feature/improve-append-perfo…
Browse files Browse the repository at this point in the history
…rmance2

Improve the performance of the append operation and also enable the s…
  • Loading branch information
josephnowak authored Sep 6, 2024
2 parents 52130e3 + 532e8c9 commit 310a502
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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.31.1",
version="0.31.2",
description="Database based in a file system storage combined with Xarray and Zarr",
author="Joseph Nowak",
author_email="josephgonowak97@gmail.com",
Expand Down
16 changes: 10 additions & 6 deletions tensordb/storages/zarr_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def append(

rewrite = False
act_coords = {k: coord for k, coord in act_data.indexes.items()}
data_to_append = {}
slices_to_append = {}
complete_data = act_data

Expand All @@ -279,9 +280,11 @@ def append(
k: slice(size, None) if k == dim else slice(0, size)
for k, size in complete_data.sizes.items()
}
append_new_data = new_data.reindex(reindex_coords, fill_value=fill_value)
data_to_append[dim] = new_data.reindex(
reindex_coords, fill_value=fill_value
)
complete_data = xr.concat(
[complete_data, append_new_data], dim=dim, fill_value=fill_value
[complete_data, data_to_append[dim]], dim=dim, fill_value=fill_value
)

complete_data = xr.Dataset(
Expand All @@ -305,17 +308,18 @@ def append(
if dim not in slices_to_append:
continue

data_to_append = complete_data.isel(**slices_to_append[dim])
data_to_append = data_to_append.chunk(self.chunks)

data = data_to_append[dim].chunk(
complete_data.isel(**slices_to_append[dim]).chunks
)
delayed_appends.append(
data_to_append.to_zarr(
data.to_zarr(
self.base_map,
append_dim=dim,
compute=compute,
synchronizer=self.synchronizer,
consolidated=True,
group=self.group,
safe_chunks=False,
)
)

Expand Down

0 comments on commit 310a502

Please sign in to comment.