|
4 | 4 | import os |
5 | 5 | import re |
6 | 6 | import shutil |
| 7 | +import six |
7 | 8 |
|
8 | 9 | from oslo_concurrency import lockutils |
9 | 10 | import xmltodict |
10 | 11 |
|
11 | 12 | import openml.utils |
12 | 13 | import openml._api_calls |
13 | 14 | from .dataset import OpenMLDataset |
14 | | -from ..exceptions import OpenMLCacheException, OpenMLServerNoResult, \ |
15 | | - OpenMLHashException |
| 15 | +from ..exceptions import OpenMLCacheException, OpenMLServerException, \ |
| 16 | + OpenMLHashException, PrivateDatasetError |
16 | 17 | from .. import config |
17 | 18 | from .._api_calls import _read_url |
18 | 19 |
|
@@ -315,13 +316,21 @@ def get_dataset(dataset_id): |
315 | 316 | did_cache_dir = _create_dataset_cache_directory(dataset_id) |
316 | 317 |
|
317 | 318 | try: |
| 319 | + remove_dataset_cache = True |
318 | 320 | description = _get_dataset_description(did_cache_dir, dataset_id) |
319 | 321 | arff_file = _get_dataset_arff(did_cache_dir, description) |
320 | 322 | features = _get_dataset_features(did_cache_dir, dataset_id) |
321 | 323 | qualities = _get_dataset_qualities(did_cache_dir, dataset_id) |
322 | | - except Exception as e: |
323 | | - _remove_dataset_cache_dir(did_cache_dir) |
324 | | - raise e |
| 324 | + remove_dataset_cache = False |
| 325 | + except OpenMLServerException as e: |
| 326 | + # if there was an exception, check if the user had access to the dataset |
| 327 | + if e.code == 112: |
| 328 | + six.raise_from(PrivateDatasetError(e.message), None) |
| 329 | + else: |
| 330 | + raise e |
| 331 | + finally: |
| 332 | + if remove_dataset_cache: |
| 333 | + _remove_dataset_cache_dir(did_cache_dir) |
325 | 334 |
|
326 | 335 | dataset = _create_dataset_from_description( |
327 | 336 | description, features, qualities, arff_file |
@@ -357,9 +366,8 @@ def _get_dataset_description(did_cache_dir, dataset_id): |
357 | 366 |
|
358 | 367 | try: |
359 | 368 | return _get_cached_dataset_description(dataset_id) |
360 | | - except (OpenMLCacheException): |
| 369 | + except OpenMLCacheException: |
361 | 370 | dataset_xml = openml._api_calls._perform_api_call("data/%d" % dataset_id) |
362 | | - |
363 | 371 | with io.open(description_file, "w", encoding='utf8') as fh: |
364 | 372 | fh.write(dataset_xml) |
365 | 373 |
|
|
0 commit comments