Skip to content

Commit c84d3a2

Browse files
committed
Fix Python 3.13 compat issue in spectral_indices #653/#799
1 parent 09e8fe4 commit c84d3a2

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Fixed
1717

1818
- `STACAPIJobDatabase.item_from()` use "datetime" from series instead of always taking "now" ([#797](https://github.com/Open-EO/openeo-python-client/issues/797))
19+
- Fix Python 3.13 compatibility issue in `openeo.extra.spectral_indices` ([#799](https://github.com/Open-EO/openeo-python-client/issues/799))
1920

2021

2122
## [0.43.0] - 2025-07-02

openeo/extra/spectral_indices/spectral_indices.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ def load_indices() -> Dict[str, dict]:
2626
# and provide an alternative mechanism to work with custom indices
2727
"resources/extra-indices-dict.json",
2828
]:
29-
with importlib_resources.files("openeo.extra.spectral_indices") / path as resource_path:
30-
data = json.loads(resource_path.read_text(encoding="utf8"))
31-
overwrites = set(specs.keys()).intersection(data["SpectralIndices"].keys())
32-
if overwrites:
33-
raise RuntimeError(f"Duplicate spectral indices: {overwrites} from {path}")
34-
specs.update(data["SpectralIndices"])
29+
resource = importlib_resources.files("openeo.extra.spectral_indices") / path
30+
data = json.loads(resource.read_text(encoding="utf8"))
31+
overwrites = set(specs.keys()).intersection(data["SpectralIndices"].keys())
32+
if overwrites:
33+
raise RuntimeError(f"Duplicate spectral indices: {overwrites} from {path}")
34+
specs.update(data["SpectralIndices"])
3535

3636
return specs
3737

@@ -40,10 +40,10 @@ def load_indices() -> Dict[str, dict]:
4040
def load_constants() -> Dict[str, float]:
4141
"""Load constants defined by Awesome Spectral Indices."""
4242
# TODO: encapsulate all this json loading in a single Awesome Spectral Indices registry class?
43-
with importlib_resources.files(
44-
"openeo.extra.spectral_indices"
45-
) / "resources/awesome-spectral-indices/constants.json" as resource_path:
46-
data = json.loads(resource_path.read_text(encoding="utf8"))
43+
resource = (
44+
importlib_resources.files("openeo.extra.spectral_indices") / "resources/awesome-spectral-indices/constants.json"
45+
)
46+
data = json.loads(resource.read_text(encoding="utf8"))
4747

4848
return {k: v["default"] for k, v in data.items() if isinstance(v["default"], (int, float))}
4949

@@ -52,10 +52,10 @@ def load_constants() -> Dict[str, float]:
5252
def _load_bands() -> Dict[str, dict]:
5353
"""Load band name mapping defined by Awesome Spectral Indices."""
5454
# TODO: encapsulate all this json loading in a single Awesome Spectral Indices registry class?
55-
with importlib_resources.files(
56-
"openeo.extra.spectral_indices"
57-
) / "resources/awesome-spectral-indices/bands.json" as resource_path:
58-
data = json.loads(resource_path.read_text(encoding="utf8"))
55+
resource = (
56+
importlib_resources.files("openeo.extra.spectral_indices") / "resources/awesome-spectral-indices/bands.json"
57+
)
58+
data = json.loads(resource.read_text(encoding="utf8"))
5959
return data
6060

6161

0 commit comments

Comments
 (0)