Skip to content

Commit

Permalink
fix: handle assets with . in the name (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill888 committed Jan 30, 2025
1 parent 8b2e5a0 commit 91e88ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion odc/loader/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,15 @@ def norm_key(k: BandIdentifier) -> BandKey:
("band", i) -> ("band", i)
"band" -> ("band", 1)
"band.3" -> ("band", 3)
"band.tiff" -> ("band.tiff", 1)
"""
if isinstance(k, str):
parts = k.rsplit(".", 1)
if len(parts) == 2:
return parts[0], int(parts[1])
try:
return parts[0], int(parts[1])
except ValueError:
return (k, 1)
return (k, 1)
return k

Expand Down
15 changes: 15 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
RasterGroupMetadata,
RasterLoadParams,
RasterSource,
norm_key,
)
from odc.stac import ParsedItem, RasterCollectionMetadata
from odc.stac.testing.stac import b_, mk_parsed_item
Expand Down Expand Up @@ -206,3 +207,17 @@ def test_tokenize(parsed_item_ab: ParsedItem):
assert tokenize(RasterLoadParams()) == tokenize(RasterLoadParams())
assert tokenize(RasterLoadParams("uint8")) == tokenize(RasterLoadParams("uint8"))
assert tokenize(RasterLoadParams("uint8")) != tokenize(RasterLoadParams("uint32"))


@pytest.mark.parametrize(
"name, expected",
[
("a", ("a", 1)),
("a.1", ("a", 1)),
("a.2", ("a", 2)),
(("b", 1), ("b", 1)),
("foo.tiff", ("foo.tiff", 1)),
],
)
def test_normkey(name, expected):
assert norm_key(name) == expected

0 comments on commit 91e88ab

Please sign in to comment.