Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions openml/_api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
)


def _create_url_from_endpoint(endpoint: str) -> str:
url = config.server
if not url.endswith("/"):
url += "/"
url += endpoint
return url.replace("=", "%3d")


def _perform_api_call(call, request_method, data=None, file_elements=None):
"""
Perform an API call at the OpenML server.
Expand Down Expand Up @@ -50,12 +58,7 @@ def _perform_api_call(call, request_method, data=None, file_elements=None):
return_value : str
Return value of the OpenML server
"""
url = config.server
if not url.endswith("/"):
url += "/"
url += call

url = url.replace("=", "%3d")
url = _create_url_from_endpoint(call)
logging.info("Starting [%s] request for the URL %s", request_method, url)
start = time.time()

Expand Down
12 changes: 9 additions & 3 deletions openml/datasets/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io
import logging
import os
from pyexpat import ExpatError
from typing import List, Dict, Union, Optional, cast

import numpy as np
Expand All @@ -19,6 +20,7 @@
from .dataset import OpenMLDataset
from ..exceptions import (
OpenMLHashException,
OpenMLServerError,
OpenMLServerException,
OpenMLPrivateDatasetError,
)
Expand Down Expand Up @@ -437,7 +439,7 @@ def get_dataset(
parquet_file = None
remove_dataset_cache = False
except OpenMLServerException as e:
# if there was an exception,
# if there was an exception
# check if the user had access to the dataset
if e.code == 112:
raise OpenMLPrivateDatasetError(e.message) from None
Expand Down Expand Up @@ -949,14 +951,18 @@ def _get_dataset_description(did_cache_dir, dataset_id):
try:
with io.open(description_file, encoding="utf8") as fh:
dataset_xml = fh.read()
description = xmltodict.parse(dataset_xml)["oml:data_set_description"]
except Exception:
url_extension = "data/{}".format(dataset_id)
dataset_xml = openml._api_calls._perform_api_call(url_extension, "get")
try:
description = xmltodict.parse(dataset_xml)["oml:data_set_description"]
except ExpatError as e:
url = openml._api_calls._create_url_from_endpoint(url_extension)
raise OpenMLServerError(f"Dataset description XML at '{url}' is malformed.") from e
with io.open(description_file, "w", encoding="utf8") as fh:
fh.write(dataset_xml)

description = xmltodict.parse(dataset_xml)["oml:data_set_description"]

return description


Expand Down
2 changes: 1 addition & 1 deletion tests/test_datasets/test_dataset_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ def _wait_for_dataset_being_processed(self, dataset_id):
try:
downloaded_dataset = openml.datasets.get_dataset(dataset_id)
break
except Exception as e:
except OpenMLServerException as e:
# returned code 273: Dataset not processed yet
# returned code 362: No qualities found
TestBase.logger.error(
Expand Down