Skip to content

Commit

Permalink
fix coordmanager non associated coord (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadtourei authored Sep 26, 2024
1 parent 3858a11 commit a555a78
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dascore/core/coordmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ def get_coord_manager(
# from dict keys.
if dims is None:
if isinstance(coords, Mapping) and all(isinstance(x, str) for x in coords):
dims = tuple(coords.keys())
dims = tuple(i for i, v in coords.items() if not isinstance(v, tuple))
elif attrs is not None and "dims" in attrs or hasattr(attrs, "dims"):
dims = tuple(attrs["dims"].split(","))
else:
Expand Down Expand Up @@ -1160,7 +1160,7 @@ def _maybe_coord_from_nested(name, coord, new_dims):
" (dimension, coord) or ((dimensions,...), coord)"
)
raise CoordError(msg)
dim_names = iterate(coord[0])
dim_names = tuple(i for i in iterate(coord[0]) if i)
# # all dims must be in the input dims or a new coord.
d1, d2 = set(dim_names), set(dims)
if (not d1.issubset(d2)) and d1 != {name}:
Expand Down
1 change: 1 addition & 0 deletions dascore/utils/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ def stack_patches(
dim_vary
The name of the dimension which can be different in values
(but not shape) and patches still added together.
If None, all dimension values must be equal.
{check_desc}
Examples
Expand Down
10 changes: 10 additions & 0 deletions tests/test_core/test_coordmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ def test_non_coord_dims(self):
assert out.shape == (10, 2)
assert out.dims == ("time", "money")

def test_not_associated_coord_1(self):
"""Ensure a not associated coord works as only input."""
coords = {"time": (None, np.arange(10))}
assert isinstance(get_coord_manager(coords), CoordManager)

def test_not_associated_coord_2(self):
"""Ensure an empty string not associated coord works as only input."""
coords = {"time": ("", np.arange(10))}
assert isinstance(get_coord_manager(coords), CoordManager)


class TestBasicCoordManager:
"""Ensure basic things work with coord managers."""
Expand Down
17 changes: 17 additions & 0 deletions tests/test_io/test_dasdae/test_dasdae.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ def written_dascore_v1_empty(tmp_path_factory):
return path


@pytest.fixture(scope="class")
@register_func(WRITTEN_FILES)
def written_dascore_correlate(tmp_path_factory, random_patch):
"""Write a correlate patch to the dascore format."""
path = tmp_path_factory.mktemp("correlate_patcc") / "correlate.hdf5"
padded_pa = random_patch.pad(time="correlate")
dft_pa = padded_pa.dft("time", real=True)
cc_pa = dft_pa.correlate(distance=[0, 1, 2], samples=True)
dc.write(cc_pa, path, "DASDAE", file_version="1")
return path


@pytest.fixture(params=WRITTEN_FILES, scope="class")
def dasdae_v1_file_path(request):
"""Gatherer fixture to iterate through each written dasedae format."""
Expand Down Expand Up @@ -101,6 +113,11 @@ def test_write_again(self, written_dascore_v1_random, random_patch):
read_patch = dc.spool(written_dascore_v1_random)[0]
assert random_patch == read_patch

def test_write_cc_patch(self, written_dascore_correlate):
"""Ensure cross correlated patches can be writen and read."""
sp_cc = dc.spool(written_dascore_correlate)
assert isinstance(sp_cc[0], dc.Patch)


class TestReadDASDAE:
"""Test for reading a dasdae format."""
Expand Down

0 comments on commit a555a78

Please sign in to comment.