diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 45e4f1bd0..074ae7add 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -7,10 +7,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Setup Python 3.7 + - name: Setup Python 3.8 uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: 3.8 - name: Install pre-commit run: | pip install pre-commit diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 05bac7967..8a48b3ca5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 23.3.0 hooks: - id: black args: [--line-length=100] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.961 + rev: v1.2.0 hooks: - id: mypy name: mypy openml @@ -20,7 +20,7 @@ repos: - types-requests - types-python-dateutil - repo: https://github.com/pycqa/flake8 - rev: 4.0.1 + rev: 6.0.0 hooks: - id: flake8 name: flake8 openml diff --git a/doc/progress.rst b/doc/progress.rst index d546ac4bd..e599a0ad3 100644 --- a/doc/progress.rst +++ b/doc/progress.rst @@ -9,15 +9,16 @@ Changelog 0.13.1 ~~~~~~ - * DOC #1241 #1229 #1231: Minor documentation fixes and resolve documentation examples not working. * ADD #1028: Add functions to delete runs, flows, datasets, and tasks (e.g., ``openml.datasets.delete_dataset``). * ADD #1144: Add locally computed results to the ``OpenMLRun`` object's representation if the run was created locally and not downloaded from the server. * ADD #1180: Improve the error message when the checksum of a downloaded dataset does not match the checksum provided by the API. * ADD #1201: Make ``OpenMLTraceIteration`` a dataclass. * DOC #1069: Add argument documentation for the ``OpenMLRun`` class. + * DOC #1241 #1229 #1231: Minor documentation fixes and resolve documentation examples not working. * FIX #1197 #559 #1131: Fix the order of ground truth and predictions in the ``OpenMLRun`` object and in ``format_prediction``. * FIX #1198: Support numpy 1.24 and higher. * FIX #1216: Allow unknown task types on the server. This is only relevant when new task types are added to the test server. + * FIX #1223: Fix mypy errors for implicit optional typing. * MAINT #1155: Add dependabot github action to automatically update other github actions. * MAINT #1199: Obtain pre-commit's flake8 from github.com instead of gitlab.com. * MAINT #1215: Support latest numpy version. diff --git a/examples/30_extended/fetch_runtimes_tutorial.py b/examples/30_extended/fetch_runtimes_tutorial.py index 1a6e5117f..107adee79 100644 --- a/examples/30_extended/fetch_runtimes_tutorial.py +++ b/examples/30_extended/fetch_runtimes_tutorial.py @@ -79,6 +79,7 @@ ) ) + # Creating utility function def print_compare_runtimes(measures): for repeat, val1 in measures["usercpu_time_millis_training"].items(): diff --git a/openml/_api_calls.py b/openml/_api_calls.py index f7b2a34c5..ade0eaf50 100644 --- a/openml/_api_calls.py +++ b/openml/_api_calls.py @@ -195,7 +195,7 @@ def _download_minio_bucket( def _download_text_file( source: str, output_path: Optional[str] = None, - md5_checksum: str = None, + md5_checksum: Optional[str] = None, exists_ok: bool = True, encoding: str = "utf8", ) -> Optional[str]: @@ -326,7 +326,6 @@ def _send_request(request_method, url, data, files=None, md5_checksum=None): if request_method == "get" and not __is_checksum_equal( response.text.encode("utf-8"), md5_checksum ): - # -- Check if encoding is not UTF-8 perhaps if __is_checksum_equal(response.content, md5_checksum): raise OpenMLHashException( diff --git a/openml/datasets/dataset.py b/openml/datasets/dataset.py index 1644ff177..a506ca450 100644 --- a/openml/datasets/dataset.py +++ b/openml/datasets/dataset.py @@ -274,7 +274,6 @@ def _get_repr_body_fields(self) -> List[Tuple[str, Union[str, int, List[str]]]]: return [(key, fields[key]) for key in order if key in fields] def __eq__(self, other): - if not isinstance(other, OpenMLDataset): return False diff --git a/openml/datasets/functions.py b/openml/datasets/functions.py index 4307c8008..8847f4d04 100644 --- a/openml/datasets/functions.py +++ b/openml/datasets/functions.py @@ -74,7 +74,6 @@ def list_datasets( output_format: str = "dict", **kwargs, ) -> Union[Dict, pd.DataFrame]: - """ Return a list of all dataset which are on OpenML. Supports large amount of results. @@ -182,7 +181,6 @@ def _list_datasets(data_id: Optional[List] = None, output_format="dict", **kwarg def __list_datasets(api_call, output_format="dict"): - xml_string = openml._api_calls._perform_api_call(api_call, "get") datasets_dict = xmltodict.parse(xml_string, force_list=("oml:dataset",)) @@ -353,7 +351,7 @@ def get_datasets( def get_dataset( dataset_id: Union[int, str], download_data: bool = True, - version: int = None, + version: Optional[int] = None, error_if_multiple: bool = False, cache_format: str = "pickle", download_qualities: bool = True, @@ -984,7 +982,7 @@ def _get_dataset_description(did_cache_dir, dataset_id): def _get_dataset_parquet( description: Union[Dict, OpenMLDataset], - cache_directory: str = None, + cache_directory: Optional[str] = None, download_all_files: bool = False, ) -> Optional[str]: """Return the path to the local parquet file of the dataset. If is not cached, it is downloaded. @@ -1051,7 +1049,9 @@ def _get_dataset_parquet( return output_file_path -def _get_dataset_arff(description: Union[Dict, OpenMLDataset], cache_directory: str = None) -> str: +def _get_dataset_arff( + description: Union[Dict, OpenMLDataset], cache_directory: Optional[str] = None +) -> str: """Return the path to the local arff file of the dataset. If is not cached, it is downloaded. Checks if the file is in the cache, if yes, return the path to the file. @@ -1173,8 +1173,8 @@ def _create_dataset_from_description( description: Dict[str, str], features_file: str, qualities_file: str, - arff_file: str = None, - parquet_file: str = None, + arff_file: Optional[str] = None, + parquet_file: Optional[str] = None, cache_format: str = "pickle", ) -> OpenMLDataset: """Create a dataset object from a description dict. diff --git a/openml/exceptions.py b/openml/exceptions.py index fe2138e76..a86434f51 100644 --- a/openml/exceptions.py +++ b/openml/exceptions.py @@ -1,5 +1,7 @@ # License: BSD 3-Clause +from typing import Optional + class PyOpenMLError(Exception): def __init__(self, message: str): @@ -20,7 +22,7 @@ class OpenMLServerException(OpenMLServerError): # Code needs to be optional to allow the exception to be picklable: # https://stackoverflow.com/questions/16244923/how-to-make-a-custom-exception-class-with-multiple-init-args-pickleable # noqa: E501 - def __init__(self, message: str, code: int = None, url: str = None): + def __init__(self, message: str, code: Optional[int] = None, url: Optional[str] = None): self.message = message self.code = code self.url = url diff --git a/openml/extensions/extension_interface.py b/openml/extensions/extension_interface.py index f33ef7543..981bf2417 100644 --- a/openml/extensions/extension_interface.py +++ b/openml/extensions/extension_interface.py @@ -166,7 +166,7 @@ def _run_model_on_fold( y_train: Optional[np.ndarray] = None, X_test: Optional[Union[np.ndarray, scipy.sparse.spmatrix]] = None, ) -> Tuple[np.ndarray, np.ndarray, "OrderedDict[str, float]", Optional["OpenMLRunTrace"]]: - """Run a model on a repeat,fold,subsample triplet of the task and return prediction information. + """Run a model on a repeat, fold, subsample triplet of the task. Returns the data that is necessary to construct the OpenML Run object. Is used by :func:`openml.runs.run_flow_on_task`. diff --git a/openml/extensions/sklearn/extension.py b/openml/extensions/sklearn/extension.py index 997a9b8ea..82d202e9c 100644 --- a/openml/extensions/sklearn/extension.py +++ b/openml/extensions/sklearn/extension.py @@ -1021,7 +1021,6 @@ def flatten_all(list_): # when deserializing the parameter sub_components_explicit.add(identifier) if isinstance(sub_component, str): - external_version = self._get_external_version_string(None, {}) dependencies = self._get_dependencies() tags = self._get_tags() @@ -1072,7 +1071,6 @@ def flatten_all(list_): parameters[k] = parameter_json elif isinstance(rval, OpenMLFlow): - # A subcomponent, for example the base model in # AdaBoostClassifier sub_components[k] = rval @@ -1762,7 +1760,6 @@ def _prediction_to_probabilities( ) if isinstance(task, (OpenMLClassificationTask, OpenMLLearningCurveTask)): - try: proba_y = model_copy.predict_proba(X_test) proba_y = pd.DataFrame(proba_y, columns=model_classes) # handles X_test as numpy diff --git a/openml/flows/functions.py b/openml/flows/functions.py index aea5cae6d..42cf9a6af 100644 --- a/openml/flows/functions.py +++ b/openml/flows/functions.py @@ -120,7 +120,6 @@ def _get_flow_description(flow_id: int) -> OpenMLFlow: try: return _get_cached_flow(flow_id) except OpenMLCacheException: - xml_file = os.path.join( openml.utils._create_cache_directory_for_id(FLOWS_CACHE_DIR_NAME, flow_id), "flow.xml", @@ -140,7 +139,6 @@ def list_flows( output_format: str = "dict", **kwargs ) -> Union[Dict, pd.DataFrame]: - """ Return a list of all flows which are on OpenML. (Supports large amount of results) @@ -329,7 +327,6 @@ def get_flow_id( def __list_flows(api_call: str, output_format: str = "dict") -> Union[Dict, pd.DataFrame]: - xml_string = openml._api_calls._perform_api_call(api_call, "get") flows_dict = xmltodict.parse(xml_string, force_list=("oml:flow",)) @@ -377,7 +374,7 @@ def _check_flow_for_server_id(flow: OpenMLFlow) -> None: def assert_flows_equal( flow1: OpenMLFlow, flow2: OpenMLFlow, - ignore_parameter_values_on_older_children: str = None, + ignore_parameter_values_on_older_children: Optional[str] = None, ignore_parameter_values: bool = False, ignore_custom_name_if_none: bool = False, check_description: bool = True, diff --git a/openml/runs/functions.py b/openml/runs/functions.py index d52b43add..ce2578208 100644 --- a/openml/runs/functions.py +++ b/openml/runs/functions.py @@ -49,8 +49,8 @@ def run_model_on_task( model: Any, task: Union[int, str, OpenMLTask], avoid_duplicate_runs: bool = True, - flow_tags: List[str] = None, - seed: int = None, + flow_tags: Optional[List[str]] = None, + seed: Optional[int] = None, add_local_measures: bool = True, upload_flow: bool = False, return_flow: bool = False, @@ -148,8 +148,8 @@ def run_flow_on_task( flow: OpenMLFlow, task: OpenMLTask, avoid_duplicate_runs: bool = True, - flow_tags: List[str] = None, - seed: int = None, + flow_tags: Optional[List[str]] = None, + seed: Optional[int] = None, add_local_measures: bool = True, upload_flow: bool = False, dataset_format: str = "dataframe", @@ -438,7 +438,7 @@ def _run_task_get_arffcontent( extension: "Extension", add_local_measures: bool, dataset_format: str, - n_jobs: int = None, + n_jobs: Optional[int] = None, ) -> Tuple[ List[List], Optional[OpenMLRunTrace], @@ -505,7 +505,6 @@ def _calculate_local_measure(sklearn_fn, openml_name): user_defined_measures_fold[openml_name] = sklearn_fn(test_y, pred_y) if isinstance(task, (OpenMLClassificationTask, OpenMLLearningCurveTask)): - for i, tst_idx in enumerate(test_indices): if task.class_labels is not None: prediction = ( @@ -549,7 +548,6 @@ def _calculate_local_measure(sklearn_fn, openml_name): ) elif isinstance(task, OpenMLRegressionTask): - for i, _ in enumerate(test_indices): truth = test_y.iloc[i] if isinstance(test_y, pd.Series) else test_y[i] arff_line = format_prediction( @@ -570,7 +568,6 @@ def _calculate_local_measure(sklearn_fn, openml_name): ) elif isinstance(task, OpenMLClusteringTask): - for i, _ in enumerate(test_indices): arff_line = [test_indices[i], pred_y[i]] # row_id, cluster ID arff_datacontent.append(arff_line) @@ -579,7 +576,6 @@ def _calculate_local_measure(sklearn_fn, openml_name): raise TypeError(type(task)) for measure in user_defined_measures_fold: - if measure not in user_defined_measures_per_fold: user_defined_measures_per_fold[measure] = OrderedDict() if rep_no not in user_defined_measures_per_fold[measure]: @@ -625,7 +621,7 @@ def _run_task_get_arffcontent_parallel_helper( sample_no: int, task: OpenMLTask, dataset_format: str, - configuration: Dict = None, + configuration: Optional[Dict] = None, ) -> Tuple[ np.ndarray, Optional[pd.DataFrame], @@ -674,7 +670,12 @@ def _run_task_get_arffcontent_parallel_helper( sample_no, ) ) - pred_y, proba_y, user_defined_measures_fold, trace, = extension._run_model_on_fold( + ( + pred_y, + proba_y, + user_defined_measures_fold, + trace, + ) = extension._run_model_on_fold( model=model, task=task, X_train=train_x, diff --git a/openml/runs/trace.py b/openml/runs/trace.py index 0b8571fe5..f6b038a55 100644 --- a/openml/runs/trace.py +++ b/openml/runs/trace.py @@ -55,7 +55,7 @@ def get_selected_iteration(self, fold: int, repeat: int) -> int: The trace iteration from the given fold and repeat that was selected as the best iteration by the search procedure """ - for (r, f, i) in self.trace_iterations: + for r, f, i in self.trace_iterations: if r == repeat and f == fold and self.trace_iterations[(r, f, i)].selected is True: return i raise ValueError( @@ -345,7 +345,6 @@ def trace_from_xml(cls, xml): @classmethod def merge_traces(cls, traces: List["OpenMLRunTrace"]) -> "OpenMLRunTrace": - merged_trace = ( OrderedDict() ) # type: OrderedDict[Tuple[int, int, int], OpenMLTraceIteration] # noqa E501 diff --git a/openml/setups/functions.py b/openml/setups/functions.py index f4fab3219..1e3d44e0b 100644 --- a/openml/setups/functions.py +++ b/openml/setups/functions.py @@ -97,7 +97,7 @@ def get_setup(setup_id): try: return _get_cached_setup(setup_id) - except (openml.exceptions.OpenMLCacheException): + except openml.exceptions.OpenMLCacheException: url_suffix = "/setup/%d" % setup_id setup_xml = openml._api_calls._perform_api_call(url_suffix, "get") with io.open(setup_file, "w", encoding="utf8") as fh: diff --git a/openml/study/study.py b/openml/study/study.py index 0cdc913f9..cfc4cab3b 100644 --- a/openml/study/study.py +++ b/openml/study/study.py @@ -73,7 +73,6 @@ def __init__( runs: Optional[List[int]], setups: Optional[List[int]], ): - self.study_id = study_id self.alias = alias self.main_entity_type = main_entity_type @@ -100,11 +99,11 @@ def id(self) -> Optional[int]: def _get_repr_body_fields(self) -> List[Tuple[str, Union[str, int, List[str]]]]: """Collect all information to display in the __repr__ body.""" - fields = { + fields: Dict[str, Any] = { "Name": self.name, "Status": self.status, "Main Entity Type": self.main_entity_type, - } # type: Dict[str, Any] + } if self.study_id is not None: fields["ID"] = self.study_id fields["Study URL"] = self.openml_url diff --git a/openml/tasks/functions.py b/openml/tasks/functions.py index 964277760..3dedc99c0 100644 --- a/openml/tasks/functions.py +++ b/openml/tasks/functions.py @@ -387,7 +387,6 @@ def get_task( def _get_task_description(task_id): - try: return _get_cached_task(task_id) except OpenMLCacheException: diff --git a/openml/tasks/split.py b/openml/tasks/split.py index dc496ef7d..bc0dac55d 100644 --- a/openml/tasks/split.py +++ b/openml/tasks/split.py @@ -70,7 +70,6 @@ def __eq__(self, other): @classmethod def _from_arff_file(cls, filename: str) -> "OpenMLSplit": - repetitions = None pkl_filename = filename.replace(".arff", ".pkl.py3") diff --git a/openml/tasks/task.py b/openml/tasks/task.py index 14a85357b..944c75b80 100644 --- a/openml/tasks/task.py +++ b/openml/tasks/task.py @@ -58,7 +58,6 @@ def __init__( evaluation_measure: Optional[str] = None, data_splits_url: Optional[str] = None, ): - self.task_id = int(task_id) if task_id is not None else None self.task_type_id = task_type_id self.task_type = task_type @@ -83,11 +82,11 @@ def id(self) -> Optional[int]: def _get_repr_body_fields(self) -> List[Tuple[str, Union[str, int, List[str]]]]: """Collect all information to display in the __repr__ body.""" - fields = { + fields: Dict[str, Any] = { "Task Type Description": "{}/tt/{}".format( openml.config.get_server_base_url(), self.task_type_id ) - } # type: Dict[str, Any] + } if self.task_id is not None: fields["Task ID"] = self.task_id fields["Task URL"] = self.openml_url @@ -125,7 +124,6 @@ def get_train_test_split_indices( repeat: int = 0, sample: int = 0, ) -> Tuple[np.ndarray, np.ndarray]: - # Replace with retrieve from cache if self.split is None: self.split = self.download_split() @@ -165,7 +163,6 @@ def download_split(self) -> OpenMLSplit: return split def get_split_dimensions(self) -> Tuple[int, int, int]: - if self.split is None: self.split = self.download_split() @@ -273,7 +270,6 @@ def get_X_and_y( return X, y def _to_dict(self) -> "OrderedDict[str, OrderedDict]": - task_container = super(OpenMLSupervisedTask, self)._to_dict() task_dict = task_container["oml:task_inputs"] @@ -285,7 +281,6 @@ def _to_dict(self) -> "OrderedDict[str, OrderedDict]": @property def estimation_parameters(self): - warn( "The estimation_parameters attribute will be " "deprecated in the future, please use " @@ -296,7 +291,6 @@ def estimation_parameters(self): @estimation_parameters.setter def estimation_parameters(self, est_parameters): - self.estimation_procedure["parameters"] = est_parameters @@ -324,7 +318,6 @@ def __init__( class_labels: Optional[List[str]] = None, cost_matrix: Optional[np.ndarray] = None, ): - super(OpenMLClassificationTask, self).__init__( task_id=task_id, task_type_id=task_type_id, @@ -436,7 +429,6 @@ def get_X( return data def _to_dict(self) -> "OrderedDict[str, OrderedDict]": - task_container = super(OpenMLClusteringTask, self)._to_dict() # Right now, it is not supported as a feature. diff --git a/openml/utils.py b/openml/utils.py index 19f77f8c6..7f99fbba2 100644 --- a/openml/utils.py +++ b/openml/utils.py @@ -72,13 +72,13 @@ def extract_xml_tags(xml_tag_name, node, allow_none=True): def _get_rest_api_type_alias(oml_object: "OpenMLBase") -> str: """Return the alias of the openml entity as it is defined for the REST API.""" - rest_api_mapping = [ + rest_api_mapping: List[Tuple[Union[Type, Tuple], str]] = [ (openml.datasets.OpenMLDataset, "data"), (openml.flows.OpenMLFlow, "flow"), (openml.tasks.OpenMLTask, "task"), (openml.runs.OpenMLRun, "run"), ((openml.study.OpenMLStudy, openml.study.OpenMLBenchmarkSuite), "study"), - ] # type: List[Tuple[Union[Type, Tuple], str]] + ] _, api_type_alias = [ (python_type, api_alias) for (python_type, api_alias) in rest_api_mapping diff --git a/setup.cfg b/setup.cfg index 156baa3bb..726c8fa73 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,11 +4,3 @@ description-file = README.md [tool:pytest] filterwarnings = ignore:the matrix subclass:PendingDeprecationWarning - -[flake8] -exclude = - # the following file and directory can be removed when the descriptions - # are shortened. More info at: - # https://travis-ci.org/openml/openml-python/jobs/590382001 - examples/30_extended/tasks_tutorial.py - examples/40_paper \ No newline at end of file diff --git a/tests/test_datasets/test_dataset.py b/tests/test_datasets/test_dataset.py index 15a801383..f288f152a 100644 --- a/tests/test_datasets/test_dataset.py +++ b/tests/test_datasets/test_dataset.py @@ -176,14 +176,14 @@ def test_get_data_with_rowid(self): self.dataset.row_id_attribute = "condition" rval, _, categorical, _ = self.dataset.get_data(include_row_id=True) self.assertIsInstance(rval, pd.DataFrame) - for (dtype, is_cat, col) in zip(rval.dtypes, categorical, rval): + for dtype, is_cat, col in zip(rval.dtypes, categorical, rval): self._check_expected_type(dtype, is_cat, rval[col]) self.assertEqual(rval.shape, (898, 39)) self.assertEqual(len(categorical), 39) rval, _, categorical, _ = self.dataset.get_data() self.assertIsInstance(rval, pd.DataFrame) - for (dtype, is_cat, col) in zip(rval.dtypes, categorical, rval): + for dtype, is_cat, col in zip(rval.dtypes, categorical, rval): self._check_expected_type(dtype, is_cat, rval[col]) self.assertEqual(rval.shape, (898, 38)) self.assertEqual(len(categorical), 38) @@ -202,7 +202,7 @@ def test_get_data_with_target_array(self): def test_get_data_with_target_pandas(self): X, y, categorical, attribute_names = self.dataset.get_data(target="class") self.assertIsInstance(X, pd.DataFrame) - for (dtype, is_cat, col) in zip(X.dtypes, categorical, X): + for dtype, is_cat, col in zip(X.dtypes, categorical, X): self._check_expected_type(dtype, is_cat, X[col]) self.assertIsInstance(y, pd.Series) self.assertEqual(y.dtype.name, "category") @@ -227,13 +227,13 @@ def test_get_data_rowid_and_ignore_and_target(self): def test_get_data_with_ignore_attributes(self): self.dataset.ignore_attribute = ["condition"] rval, _, categorical, _ = self.dataset.get_data(include_ignore_attribute=True) - for (dtype, is_cat, col) in zip(rval.dtypes, categorical, rval): + for dtype, is_cat, col in zip(rval.dtypes, categorical, rval): self._check_expected_type(dtype, is_cat, rval[col]) self.assertEqual(rval.shape, (898, 39)) self.assertEqual(len(categorical), 39) rval, _, categorical, _ = self.dataset.get_data(include_ignore_attribute=False) - for (dtype, is_cat, col) in zip(rval.dtypes, categorical, rval): + for dtype, is_cat, col in zip(rval.dtypes, categorical, rval): self._check_expected_type(dtype, is_cat, rval[col]) self.assertEqual(rval.shape, (898, 38)) self.assertEqual(len(categorical), 38) diff --git a/tests/test_datasets/test_dataset_functions.py b/tests/test_datasets/test_dataset_functions.py index 45a64ab8a..d1c44d424 100644 --- a/tests/test_datasets/test_dataset_functions.py +++ b/tests/test_datasets/test_dataset_functions.py @@ -73,7 +73,6 @@ def _remove_pickle_files(self): pass def _get_empty_param_for_dataset(self): - return { "name": None, "description": None, @@ -604,7 +603,6 @@ def test__retrieve_class_labels(self): self.assertEqual(labels, ["C", "H", "G"]) def test_upload_dataset_with_url(self): - dataset = OpenMLDataset( "%s-UploadTestWithURL" % self._get_sentinel(), "test", @@ -721,7 +719,6 @@ def test_attributes_arff_from_df_unknown_dtype(self): attributes_arff_from_df(df) def test_create_dataset_numpy(self): - data = np.array([[1, 2, 3], [1.2, 2.5, 3.8], [2, 5, 8], [0, 1, 0]]).T attributes = [("col_{}".format(i), "REAL") for i in range(data.shape[1])] @@ -757,7 +754,6 @@ def test_create_dataset_numpy(self): self.assertEqual(_get_online_dataset_format(dataset.id), "arff", "Wrong format for dataset") def test_create_dataset_list(self): - data = [ ["a", "sunny", 85.0, 85.0, "FALSE", "no"], ["b", "sunny", 80.0, 90.0, "TRUE", "no"], @@ -814,7 +810,6 @@ def test_create_dataset_list(self): self.assertEqual(_get_online_dataset_format(dataset.id), "arff", "Wrong format for dataset") def test_create_dataset_sparse(self): - # test the scipy.sparse.coo_matrix sparse_data = scipy.sparse.coo_matrix( ([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], ([0, 1, 1, 2, 2, 3, 3], [0, 1, 2, 0, 2, 0, 1])) @@ -892,7 +887,6 @@ def test_create_dataset_sparse(self): ) def test_create_invalid_dataset(self): - data = [ "sunny", "overcast", @@ -956,7 +950,6 @@ def test_topic_api_error(self): ) def test_get_online_dataset_format(self): - # Phoneme dataset dataset_id = 77 dataset = openml.datasets.get_dataset(dataset_id, download_data=False) @@ -1411,7 +1404,6 @@ def test_get_dataset_cache_format_pickle(self): self.assertEqual(len(attribute_names), X.shape[1]) def test_get_dataset_cache_format_feather(self): - dataset = openml.datasets.get_dataset(128, cache_format="feather") dataset.get_data() diff --git a/tests/test_extensions/test_sklearn_extension/test_sklearn_extension.py b/tests/test_extensions/test_sklearn_extension/test_sklearn_extension.py index 86ae419d2..2b07796ed 100644 --- a/tests/test_extensions/test_sklearn_extension/test_sklearn_extension.py +++ b/tests/test_extensions/test_sklearn_extension/test_sklearn_extension.py @@ -117,7 +117,6 @@ def _get_expected_pipeline_description(self, model: Any) -> str: def _serialization_test_helper( self, model, X, y, subcomponent_parameters, dependencies_mock_call_count=(1, 2) ): - # Regex pattern for memory addresses of style 0x7f8e0f31ecf8 pattern = re.compile("0x[0-9a-f]{12}") @@ -1050,7 +1049,6 @@ def test_serialize_cvobject(self): @pytest.mark.sklearn def test_serialize_simple_parameter_grid(self): - # We cannot easily test for scipy random variables in here, but they # should be covered @@ -1568,7 +1566,6 @@ def test_obtain_parameter_values_flow_not_from_server(self): @pytest.mark.sklearn def test_obtain_parameter_values(self): - model = sklearn.model_selection.RandomizedSearchCV( estimator=sklearn.ensemble.RandomForestClassifier(n_estimators=5), param_distributions={ @@ -2035,7 +2032,6 @@ def test_run_model_on_fold_clustering(self): @pytest.mark.sklearn def test__extract_trace_data(self): - param_grid = { "hidden_layer_sizes": [[5, 5], [10, 10], [20, 20]], "activation": ["identity", "logistic", "tanh", "relu"], @@ -2078,7 +2074,6 @@ def test__extract_trace_data(self): self.assertEqual(len(trace_iteration.parameters), len(param_grid)) for param in param_grid: - # Prepend with the "parameter_" prefix param_in_trace = "parameter_%s" % param self.assertIn(param_in_trace, trace_iteration.parameters) diff --git a/tests/test_runs/test_run.py b/tests/test_runs/test_run.py index 67e15d62b..062d5a6aa 100644 --- a/tests/test_runs/test_run.py +++ b/tests/test_runs/test_run.py @@ -26,7 +26,6 @@ class TestRun(TestBase): # less than 1 seconds def test_tagging(self): - runs = openml.runs.list_runs(size=1) run_id = list(runs.keys())[0] run = openml.runs.get_run(run_id) @@ -120,7 +119,6 @@ def _check_array(array, type_): @pytest.mark.sklearn def test_to_from_filesystem_vanilla(self): - model = Pipeline( [ ("imputer", SimpleImputer(strategy="mean")), @@ -157,7 +155,6 @@ def test_to_from_filesystem_vanilla(self): @pytest.mark.sklearn @pytest.mark.flaky() def test_to_from_filesystem_search(self): - model = Pipeline( [ ("imputer", SimpleImputer(strategy="mean")), @@ -193,7 +190,6 @@ def test_to_from_filesystem_search(self): @pytest.mark.sklearn def test_to_from_filesystem_no_model(self): - model = Pipeline( [("imputer", SimpleImputer(strategy="mean")), ("classifier", DummyClassifier())] ) @@ -321,7 +317,6 @@ def test_publish_with_local_loaded_flow(self): @pytest.mark.sklearn def test_offline_and_online_run_identical(self): - extension = openml.extensions.sklearn.SklearnExtension() for model, task in self._get_models_tasks_for_tests(): diff --git a/tests/test_runs/test_run_functions.py b/tests/test_runs/test_run_functions.py index 91dd4ce5e..4a5f2d675 100644 --- a/tests/test_runs/test_run_functions.py +++ b/tests/test_runs/test_run_functions.py @@ -635,7 +635,6 @@ def test_run_and_upload_linear_regression(self): @pytest.mark.sklearn def test_run_and_upload_pipeline_dummy_pipeline(self): - pipeline1 = Pipeline( steps=[ ("scaler", StandardScaler(with_mean=False)), @@ -718,7 +717,6 @@ def get_ct_cf(nominal_indices, numeric_indices): ) @mock.patch("warnings.warn") def test_run_and_upload_knn_pipeline(self, warnings_mock): - cat_imp = make_pipeline( SimpleImputer(strategy="most_frequent"), OneHotEncoder(handle_unknown="ignore") ) @@ -935,7 +933,6 @@ def test_initialize_cv_from_run(self): self.assertEqual(modelR[-1].cv.random_state, 62501) def _test_local_evaluations(self, run): - # compare with the scores in user defined measures accuracy_scores_provided = [] for rep in run.fold_evaluations["predictive_accuracy"].keys(): @@ -990,7 +987,6 @@ def test_local_run_swapped_parameter_order_model(self): reason="SimpleImputer doesn't handle mixed type DataFrame as input", ) def test_local_run_swapped_parameter_order_flow(self): - # construct sci-kit learn classifier clf = Pipeline( steps=[ @@ -1020,7 +1016,6 @@ def test_local_run_swapped_parameter_order_flow(self): reason="SimpleImputer doesn't handle mixed type DataFrame as input", ) def test_local_run_metric_score(self): - # construct sci-kit learn classifier clf = Pipeline( steps=[ diff --git a/tests/test_runs/test_trace.py b/tests/test_runs/test_trace.py index 6e8a7afba..d08c99e88 100644 --- a/tests/test_runs/test_trace.py +++ b/tests/test_runs/test_trace.py @@ -28,7 +28,6 @@ def test_get_selected_iteration(self): ValueError, "Could not find the selected iteration for rep/fold 3/3", ): - trace.get_selected_iteration(3, 3) def test_initialization(self): diff --git a/tests/test_setups/test_setup_functions.py b/tests/test_setups/test_setup_functions.py index 73a691d84..be8743282 100644 --- a/tests/test_setups/test_setup_functions.py +++ b/tests/test_setups/test_setup_functions.py @@ -54,7 +54,6 @@ def test_nonexisting_setup_exists(self): self.assertFalse(setup_id) def _existing_setup_exists(self, classif): - flow = self.extension.model_to_flow(classif) flow.name = "TEST%s%s" % (get_sentinel(), flow.name) flow.publish() diff --git a/tests/test_tasks/test_classification_task.py b/tests/test_tasks/test_classification_task.py index c4f74c5ce..4f03c77fc 100644 --- a/tests/test_tasks/test_classification_task.py +++ b/tests/test_tasks/test_classification_task.py @@ -7,18 +7,15 @@ class OpenMLClassificationTaskTest(OpenMLSupervisedTaskTest): - __test__ = True def setUp(self, n_levels: int = 1): - super(OpenMLClassificationTaskTest, self).setUp() self.task_id = 119 # diabetes self.task_type = TaskType.SUPERVISED_CLASSIFICATION self.estimation_procedure = 1 def test_get_X_and_Y(self): - X, Y = super(OpenMLClassificationTaskTest, self).test_get_X_and_Y() self.assertEqual((768, 8), X.shape) self.assertIsInstance(X, np.ndarray) @@ -27,13 +24,11 @@ def test_get_X_and_Y(self): self.assertEqual(Y.dtype, int) def test_download_task(self): - task = super(OpenMLClassificationTaskTest, self).test_download_task() self.assertEqual(task.task_id, self.task_id) self.assertEqual(task.task_type_id, TaskType.SUPERVISED_CLASSIFICATION) self.assertEqual(task.dataset_id, 20) def test_class_labels(self): - task = get_task(self.task_id) self.assertEqual(task.class_labels, ["tested_negative", "tested_positive"]) diff --git a/tests/test_tasks/test_clustering_task.py b/tests/test_tasks/test_clustering_task.py index c5a7a3829..d7a414276 100644 --- a/tests/test_tasks/test_clustering_task.py +++ b/tests/test_tasks/test_clustering_task.py @@ -8,11 +8,9 @@ class OpenMLClusteringTaskTest(OpenMLTaskTest): - __test__ = True def setUp(self, n_levels: int = 1): - super(OpenMLClusteringTaskTest, self).setUp() self.task_id = 146714 self.task_type = TaskType.CLUSTERING diff --git a/tests/test_tasks/test_learning_curve_task.py b/tests/test_tasks/test_learning_curve_task.py index b1422d308..b3543f9ca 100644 --- a/tests/test_tasks/test_learning_curve_task.py +++ b/tests/test_tasks/test_learning_curve_task.py @@ -7,18 +7,15 @@ class OpenMLLearningCurveTaskTest(OpenMLSupervisedTaskTest): - __test__ = True def setUp(self, n_levels: int = 1): - super(OpenMLLearningCurveTaskTest, self).setUp() self.task_id = 801 # diabetes self.task_type = TaskType.LEARNING_CURVE self.estimation_procedure = 13 def test_get_X_and_Y(self): - X, Y = super(OpenMLLearningCurveTaskTest, self).test_get_X_and_Y() self.assertEqual((768, 8), X.shape) self.assertIsInstance(X, np.ndarray) @@ -27,13 +24,11 @@ def test_get_X_and_Y(self): self.assertEqual(Y.dtype, int) def test_download_task(self): - task = super(OpenMLLearningCurveTaskTest, self).test_download_task() self.assertEqual(task.task_id, self.task_id) self.assertEqual(task.task_type_id, TaskType.LEARNING_CURVE) self.assertEqual(task.dataset_id, 20) def test_class_labels(self): - task = get_task(self.task_id) self.assertEqual(task.class_labels, ["tested_negative", "tested_positive"]) diff --git a/tests/test_tasks/test_regression_task.py b/tests/test_tasks/test_regression_task.py index c38d8fa91..c958bb3dd 100644 --- a/tests/test_tasks/test_regression_task.py +++ b/tests/test_tasks/test_regression_task.py @@ -12,7 +12,6 @@ class OpenMLRegressionTaskTest(OpenMLSupervisedTaskTest): - __test__ = True def setUp(self, n_levels: int = 1): @@ -48,7 +47,6 @@ def setUp(self, n_levels: int = 1): self.estimation_procedure = 7 def test_get_X_and_Y(self): - X, Y = super(OpenMLRegressionTaskTest, self).test_get_X_and_Y() self.assertEqual((194, 32), X.shape) self.assertIsInstance(X, np.ndarray) @@ -57,7 +55,6 @@ def test_get_X_and_Y(self): self.assertEqual(Y.dtype, float) def test_download_task(self): - task = super(OpenMLRegressionTaskTest, self).test_download_task() self.assertEqual(task.task_id, self.task_id) self.assertEqual(task.task_type_id, TaskType.SUPERVISED_REGRESSION) diff --git a/tests/test_tasks/test_supervised_task.py b/tests/test_tasks/test_supervised_task.py index 4e1a89f6e..69b6a3c1d 100644 --- a/tests/test_tasks/test_supervised_task.py +++ b/tests/test_tasks/test_supervised_task.py @@ -24,11 +24,9 @@ def setUpClass(cls): super(OpenMLSupervisedTaskTest, cls).setUpClass() def setUp(self, n_levels: int = 1): - super(OpenMLSupervisedTaskTest, self).setUp() def test_get_X_and_Y(self) -> Tuple[np.ndarray, np.ndarray]: - task = get_task(self.task_id) X, Y = task.get_X_and_y() return X, Y diff --git a/tests/test_tasks/test_task.py b/tests/test_tasks/test_task.py index 318785991..09a0024ac 100644 --- a/tests/test_tasks/test_task.py +++ b/tests/test_tasks/test_task.py @@ -28,15 +28,12 @@ def setUpClass(cls): super(OpenMLTaskTest, cls).setUpClass() def setUp(self, n_levels: int = 1): - super(OpenMLTaskTest, self).setUp() def test_download_task(self): - return get_task(self.task_id) def test_upload_task(self): - # We don't know if the task in question already exists, so we try a few times. Checking # beforehand would not be an option because a concurrent unit test could potentially # create the same task and make this unit test fail (i.e. getting a dataset and creating @@ -74,7 +71,6 @@ def test_upload_task(self): ) def _get_compatible_rand_dataset(self) -> List: - compatible_datasets = [] active_datasets = list_datasets(status="active") @@ -107,7 +103,6 @@ def _get_compatible_rand_dataset(self) -> List: # return compatible_datasets[random_dataset_pos] def _get_random_feature(self, dataset_id: int) -> str: - random_dataset = get_dataset(dataset_id) # necessary loop to overcome string and date type # features.