Skip to content

Commit 4c462ce

Browse files
VictorVerhaertsoxofaan
authored andcommitted
made warning message more explicit
1 parent ae48957 commit 4c462ce

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

openeo/rest/datacube.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,12 @@ def load_stac(
450450
type="bands",
451451
label=None,
452452
)
453-
if all(metadata.band_dimension.contains_band(b) for b in bands):
453+
missing_bands = [b for b in bands if not metadata.band_dimension.contains_band(b)]
454+
if len(missing_bands) == 0:
454455
metadata = metadata.filter_bands(band_names=bands)
455456
else:
456457
logging.warning(
457-
"Some bands are not available in the collection metadata. Using requested bands as is."
458+
f"Bands {missing_bands} are not available in the collection metadata. Using requested bands as is."
458459
)
459460
metadata = metadata.rename_labels(dimension="bands", target=bands)
460461
except Exception as e:

tests/rest/test_connection.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,12 +2975,16 @@ def test_load_stac_band_filtering(self, con120, tmp_path, caplog):
29752975
# Test with non-existing bands in the collection metadata
29762976
cube = con120.load_stac(str(stac_path), bands=["B04"])
29772977
assert cube.metadata.band_names == ["B04"]
2978-
assert "Some bands are not available in the collection metadata. Using requested bands as is." in caplog.text
2978+
expected_warning = "Bands ['B04'] are not available in the collection metadata. Using requested bands as is."
2979+
assert expected_warning in caplog.text
29792980
caplog.clear()
29802981

2981-
cube = con120.load_stac(str(stac_path), bands=["B03", "B04"])
2982-
assert cube.metadata.band_names == ["B03", "B04"]
2983-
assert "Some bands are not available in the collection metadata. Using requested bands as is." in caplog.text
2982+
cube = con120.load_stac(str(stac_path), bands=["B03", "B04", "B05"])
2983+
assert cube.metadata.band_names == ["B03", "B04", "B05"]
2984+
expected_warning = (
2985+
"Bands ['B04', 'B05'] are not available in the collection metadata. Using requested bands as is."
2986+
)
2987+
assert expected_warning in caplog.text
29842988
caplog.clear()
29852989

29862990
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)