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

Fixing again the issue of the empty coords on reindex with pad method #134

Merged
merged 1 commit into from
Nov 5, 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
Fixing again the issue of the empty coords on reindex with pad method
  • Loading branch information
josephnowak committed Nov 5, 2024
commit 0acd02c49aad50e040e04eb316dca62de7427934
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