Skip to content

Commit 922554c

Browse files
committed
add suggestions, also for dataset functions
1 parent 36ec686 commit 922554c

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

openml/datasets/functions.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,17 @@ def _create_dataset_cache_directory(dataset_id):
480480
str
481481
Path of the created dataset cache directory.
482482
"""
483-
dataset_cache_dir = os.path.join(config.get_cache_directory(), "datasets", str(dataset_id))
484-
try:
485-
os.makedirs(dataset_cache_dir)
486-
except (OSError, IOError):
487-
# TODO add debug information!
483+
dataset_cache_dir = os.path.join(
484+
config.get_cache_directory(),
485+
"datasets",
486+
str(dataset_id),
487+
)
488+
if os.path.exists(dataset_cache_dir) and os.path.isdir(dataset_cache_dir):
488489
pass
490+
elif os.path.exists(dataset_cache_dir) and not os.path.isdir(dataset_cache_dir):
491+
raise ValueError('Dataset cache dir exists but is not a directory!')
492+
else:
493+
os.makedirs(dataset_cache_dir)
489494
return dataset_cache_dir
490495

491496

@@ -498,13 +503,10 @@ def _remove_dataset_cache_dir(did_cache_dir):
498503
----------
499504
"""
500505
try:
501-
os.rmdir(did_cache_dir)
506+
shutil.rmtree(did_cache_dir)
502507
except (OSError, IOError):
503-
try:
504-
shutil.rmtree(did_cache_dir)
505-
except (OSError, IOError):
506-
raise ValueError('Cannot remove faulty dataset cache directory %s.'
507-
'Please do this manually!' % did_cache_dir)
508+
raise ValueError('Cannot remove faulty dataset cache directory %s.'
509+
'Please do this manually!' % did_cache_dir)
508510

509511

510512
def _create_dataset_from_description(description, features, qualities, arff_file):

openml/tasks/functions.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,12 @@ def _create_task_cache_directory(task_id):
283283
task_cache_dir = os.path.join(
284284
config.get_cache_directory(), "tasks", str(task_id)
285285
)
286-
try:
287-
os.makedirs(task_cache_dir)
288-
except (OSError, IOError):
289-
# TODO add debug information!
286+
if os.path.exists(task_cache_dir) and os.path.isdir(task_cache_dir):
290287
pass
288+
elif os.path.exists(task_cache_dir) and not os.path.isdir(task_cache_dir):
289+
raise ValueError('Task cache dir exists but is not a directory!')
290+
else:
291+
os.makedirs(task_cache_dir)
291292
return task_cache_dir
292293

293294

@@ -300,13 +301,10 @@ def _remove_task_cache_dir(tid_cache_dir):
300301
----------
301302
"""
302303
try:
303-
os.rmdir(tid_cache_dir)
304+
shutil.rmtree(tid_cache_dir)
304305
except (OSError, IOError):
305-
try:
306-
shutil.rmtree(tid_cache_dir)
307-
except (OSError, IOError):
308-
raise ValueError('Cannot remove faulty task cache directory %s.'
309-
'Please do this manually!' % tid_cache_dir)
306+
raise ValueError('Cannot remove faulty task cache directory %s.'
307+
'Please do this manually!' % tid_cache_dir)
310308

311309

312310
def _create_task_from_xml(xml):

0 commit comments

Comments
 (0)