diff --git a/openml/datasets/functions.py b/openml/datasets/functions.py index 7e3fd84210..22f87b80a8 100644 --- a/openml/datasets/functions.py +++ b/openml/datasets/functions.py @@ -279,32 +279,28 @@ def _load_features_from_file(features_file: str) -> Dict: return xml_dict["oml:data_features"] -def check_datasets_active(dataset_ids): - """Check if the dataset ids provided are active. +def check_datasets_active(dataset_ids: List[int]) -> Dict[int, bool]: + """ Check if the dataset ids provided are active. Parameters ---------- - dataset_ids : iterable - Integers representing dataset ids. + dataset_ids : List[int] + A list of integers representing dataset ids. Returns ------- dict A dictionary with items {did: bool} """ - dataset_list = list_datasets() - dataset_ids = sorted(dataset_ids) + dataset_list = list_datasets(status='all') active = {} - for dataset in dataset_list: - active[dataset['did']] = dataset['status'] == 'active' - for did in dataset_ids: - if did not in active: - raise ValueError('Could not find dataset {} in ' - 'OpenML dataset list.'.format(did)) - - active = {did: active[did] for did in dataset_ids} + dataset = dataset_list.get(did, None) + if dataset is None: + raise ValueError('Could not find dataset {} in OpenML dataset list.'.format(did)) + else: + active[did] = (dataset['status'] == 'active') return active diff --git a/tests/test_datasets/test_dataset_functions.py b/tests/test_datasets/test_dataset_functions.py index ff6d1c6c4e..5f404110f9 100644 --- a/tests/test_datasets/test_dataset_functions.py +++ b/tests/test_datasets/test_dataset_functions.py @@ -1,4 +1,3 @@ -import unittest import os import random from itertools import product @@ -206,10 +205,11 @@ def test_list_datasets_empty(self): self.assertIsInstance(datasets, dict) - @unittest.skip('See https://github.com/openml/openml-python/issues/149') def test_check_datasets_active(self): - active = openml.datasets.check_datasets_active([1, 17]) - self.assertTrue(active[1]) + # Have to test on live because there is no deactivated dataset on the test server. + openml.config.server = self.production_server + active = openml.datasets.check_datasets_active([2, 17]) + self.assertTrue(active[2]) self.assertFalse(active[17]) self.assertRaisesRegex( ValueError, @@ -217,6 +217,7 @@ def test_check_datasets_active(self): openml.datasets.check_datasets_active, [79], ) + openml.config.server = self.test_server def test_get_datasets(self): dids = [1, 2]