Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 91e88ab

Browse files
committedJan 30, 2025·
fix: handle assets with . in the name (#191)
1 parent 8b2e5a0 commit 91e88ab

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎odc/loader/types.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,15 @@ def norm_key(k: BandIdentifier) -> BandKey:
582582
("band", i) -> ("band", i)
583583
"band" -> ("band", 1)
584584
"band.3" -> ("band", 3)
585+
"band.tiff" -> ("band.tiff", 1)
585586
"""
586587
if isinstance(k, str):
587588
parts = k.rsplit(".", 1)
588589
if len(parts) == 2:
589-
return parts[0], int(parts[1])
590+
try:
591+
return parts[0], int(parts[1])
592+
except ValueError:
593+
return (k, 1)
590594
return (k, 1)
591595
return k
592596

‎tests/test_model.py

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
RasterGroupMetadata,
1111
RasterLoadParams,
1212
RasterSource,
13+
norm_key,
1314
)
1415
from odc.stac import ParsedItem, RasterCollectionMetadata
1516
from odc.stac.testing.stac import b_, mk_parsed_item
@@ -206,3 +207,17 @@ def test_tokenize(parsed_item_ab: ParsedItem):
206207
assert tokenize(RasterLoadParams()) == tokenize(RasterLoadParams())
207208
assert tokenize(RasterLoadParams("uint8")) == tokenize(RasterLoadParams("uint8"))
208209
assert tokenize(RasterLoadParams("uint8")) != tokenize(RasterLoadParams("uint32"))
210+
211+
212+
@pytest.mark.parametrize(
213+
"name, expected",
214+
[
215+
("a", ("a", 1)),
216+
("a.1", ("a", 1)),
217+
("a.2", ("a", 2)),
218+
(("b", 1), ("b", 1)),
219+
("foo.tiff", ("foo.tiff", 1)),
220+
],
221+
)
222+
def test_normkey(name, expected):
223+
assert norm_key(name) == expected

0 commit comments

Comments
 (0)
Please sign in to comment.