Skip to content

Commit

Permalink
Merge pull request #134 from josephnowak/feature/improve-the-reindex-…
Browse files Browse the repository at this point in the history
…with-pad

Fixing again the issue of the empty coords on reindex with pad method
  • Loading branch information
josephnowak authored Nov 5, 2024
2 parents b8fddfa + 0acd02c commit 1b904c5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[project]
name = "tensordb"
version = "0.32.3"
version = "0.32.4"
description = "Database based in a file system storage combined with Xarray and Zarr"
keywords = ["Database Files Xarray Handler Zarr Store Read Write Append Update Upsert Backup Delete S3"]
readme = "README.md"
Expand Down
4 changes: 3 additions & 1 deletion src/tensordb/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ def reindex_with_pad(
"The bfill method is not implemented for the moment"
)

is_coord_empty = False
reindex_data = data.copy()
reindex_mapped_pad_coords = {}
reindex_mapped_coords = {}
Expand All @@ -880,6 +881,7 @@ def reindex_with_pad(
if pad_width <= 0:
continue
data_coord = data.coords[dim].to_numpy()
is_coord_empty |= len(data_coord) == 0
total_coord = np.union1d(np.array(coord), data_coord)

auto_map = {c: i for i, c in enumerate(total_coord)}
Expand All @@ -896,7 +898,7 @@ def reindex_with_pad(
inv_autoincrement_map[dim] = {v: k for k, v in auto_map.items()}
pad_widths[dim] = (0, pad_width)

if not reindex_mapped_pad_coords:
if not reindex_mapped_pad_coords or is_coord_empty:
data = data.reindex(coords, fill_value=fill_value, method=method)
if apply_chunk:
data = data.chunk(preferred_chunks)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def test_rolling_overlap(window, apply_ffill):
)
@pytest.mark.parametrize(
"slices",
[{"a": [0, 3, 4], "b": [1, 3]}, {}, {"a": [0, 1], "b": [0]}],
[{"a": [0, 3, 4], "b": [1, 3]}, {}, {"a": [0, 1], "b": [0]}, {"a": [1], "b": []}],
)
@pytest.mark.parametrize(
"coords",
Expand Down

0 comments on commit 1b904c5

Please sign in to comment.