Skip to content

Commit c9ada15

Browse files
hxrshxzPGijsberspre-commit-ci[bot]
authored
Add coverage for ontology support to dataset features endpoint (#262)
Closes #237 Fetches ontology URIs from `data_feature_description` and includes them in `GET /datasets/features/{dataset_id}` responses, achieving feature parity with the PHP API. --------- Co-authored-by: Pieter Gijsbers <p.gijsbers@tue.nl> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c617d6d commit c9ada15

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

tests/routers/openml/datasets_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,24 @@ async def test_dataset_features(py_api: httpx.AsyncClient) -> None:
175175
]
176176

177177

178+
async def test_dataset_features_with_ontology(py_api: httpx.AsyncClient) -> None:
179+
# Dataset 11 has ontology data for features 1, 2, and 3
180+
response = await py_api.get("/datasets/features/11")
181+
assert response.status_code == HTTPStatus.OK
182+
features = {f["index"]: f for f in response.json()}
183+
assert features[1]["ontology"] == ["https://en.wikipedia.org/wiki/Service_(motor_vehicle)"]
184+
assert features[2]["ontology"] == [
185+
"https://en.wikipedia.org/wiki/Car_door",
186+
"https://en.wikipedia.org/wiki/Door",
187+
]
188+
assert features[3]["ontology"] == [
189+
"https://en.wikipedia.org/wiki/Passenger_vehicles_in_the_United_States"
190+
]
191+
# Features without ontology should not include the field
192+
assert "ontology" not in features[0]
193+
assert "ontology" not in features[4]
194+
195+
178196
async def test_dataset_features_no_access(py_api: httpx.AsyncClient) -> None:
179197
response = await py_api.get("/datasets/features/130")
180198
assert response.status_code == HTTPStatus.FORBIDDEN

tests/routers/openml/migration/datasets_migration_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ async def test_datasets_feature_is_identical(
260260
# The old API returns a str if there is only a single element
261261
feature["nominal_value"] = values if len(values) > 1 else values[0]
262262
elif key == "ontology":
263-
del feature[key] # Added back in with follow up PR #262
263+
# The old API returns a str if there is only a single element
264+
values = feature.pop(key)
265+
feature["ontology"] = values if len(values) > 1 else values[0]
264266
else:
265267
# The old API formats bool as string in lower-case
266268
feature[key] = str(value) if not isinstance(value, bool) else str(value).lower()
267269
original_features = original.json()["data_features"]["feature"]
268-
for feature in original_features:
269-
feature.pop("ontology", None)
270270
assert python_body == original_features

0 commit comments

Comments
 (0)