Skip to content

Commit 94ed2a6

Browse files
committed
update: cache_path_from_response -> cache_path_from_url
1 parent ac3b903 commit 94ed2a6

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

openml/_api/clients/http.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,10 +842,8 @@ def write_to_file(response: Response, path: Path, encoding: str) -> None:
842842
handler(response, file_path, encoding)
843843
return file_path
844844

845-
def cache_path_from_response(self, response: Response) -> Path:
846-
url = response.url
847-
url = urljoin(self.server, url)
848-
849-
key = self.cache.get_key(url, params={})
845+
def cache_path_from_url(self, url: str) -> Path:
846+
full_url = urljoin(self.server, url)
847+
key = self.cache.get_key(full_url, params={})
850848
path = self.cache._key_to_path(key)
851849
return path / self.cache._get_body_filename_from_path(path)

openml/_api/resources/dataset.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ def _download_file(self, url_ext: str) -> Path:
669669
-------
670670
Path
671671
"""
672-
response = self._http.get(url_ext, enable_cache=True)
673-
return self._http.cache_path_from_response(response)
672+
self._http.get(url_ext, enable_cache=True)
673+
return self._http.cache_path_from_url(url_ext)
674674

675675
def download_features_file(self, dataset_id: int) -> Path:
676676
"""Download features file.
@@ -776,8 +776,9 @@ def download_dataset_arff(
776776
raise TypeError("`description` should be either OpenMLDataset or Dict.")
777777

778778
try:
779-
response = self._http.get(url, enable_cache=True, md5_checksum=md5_checksum_fixture)
780-
output_file_path = self._http.cache_path_from_response(response)
779+
# save the file in cache and get it's path
780+
self._http.get(url, enable_cache=True, md5_checksum=md5_checksum_fixture)
781+
output_file_path = self._http.cache_path_from_url(url)
781782
except OpenMLHashException as e:
782783
additional_info = f" Raised when downloading dataset {did}."
783784
e.args = (e.args[0] + additional_info,)
@@ -1368,8 +1369,8 @@ def _download_file(self, url_ext: str) -> Path:
13681369
-------
13691370
Path
13701371
"""
1371-
response = self._http.get(url_ext, enable_cache=True)
1372-
return self._http.cache_path_from_response(response)
1372+
self._http.get(url_ext, enable_cache=True)
1373+
return self._http.cache_path_from_url(url_ext)
13731374

13741375
def download_features_file(self, dataset_id: int) -> Path:
13751376
"""Download features file.
@@ -1471,8 +1472,9 @@ def download_dataset_arff(
14711472
raise TypeError("`description` should be either OpenMLDataset or Dict.")
14721473

14731474
try:
1474-
response = self._http.get(url, enable_cache=True)
1475-
output_file_path = self._http.cache_path_from_response(response)
1475+
# save the file in cache and get it's path
1476+
self._http.get(url, enable_cache=True)
1477+
output_file_path = self._http.cache_path_from_url(url)
14761478
except OpenMLHashException as e:
14771479
additional_info = f" Raised when downloading dataset {did}."
14781480
e.args = (e.args[0] + additional_info,)

0 commit comments

Comments
 (0)