Skip to content

Commit 9e7d3e2

Browse files
[ADD] Coverage calculation (#224)
* [ADD] Coverage calculation * [Fix] Flake8 * [fix] rebase artifacts * [Fix] smac reqs * [Fix] Make traditional test robust * [Fix] unit test * [Fix] test_evaluate * [Fix] Try more time for cross validation * Fix mypy post rebase * Fix unit test
1 parent f9fe056 commit 9e7d3e2

19 files changed

+426
-209
lines changed

.codecov.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#see https://github.com/codecov/support/wiki/Codecov-Yaml
2+
codecov:
3+
notify:
4+
require_ci_to_pass: yes
5+
6+
coverage:
7+
precision: 2 # 2 = xx.xx%, 0 = xx%
8+
round: nearest # how coverage is rounded: down/up/nearest
9+
range: 10...90 # custom range of coverage colors from red -> yellow -> green
10+
status:
11+
# https://codecov.readme.io/v1.0/docs/commit-status
12+
project:
13+
default:
14+
against: auto
15+
target: 70% # specify the target coverage for each commit status
16+
threshold: 50% # allow this little decrease on project
17+
# https://github.com/codecov/support/wiki/Filtering-Branches
18+
# branches: master
19+
if_ci_failed: error
20+
# https://github.com/codecov/support/wiki/Patch-Status
21+
patch:
22+
default:
23+
against: auto
24+
target: 30% # specify the target "X%" coverage to hit
25+
threshold: 50% # allow this much decrease on patch
26+
changes: false
27+
28+
parsers:
29+
gcov:
30+
branch_detection:
31+
conditional: true
32+
loop: true
33+
macro: false
34+
method: false
35+
javascript:
36+
enable_partials: false
37+
38+
comment:
39+
layout: header, diff
40+
require_changes: false
41+
behavior: default # update if exists else create new
42+
branches: *

.coveragerc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# .coveragerc to control coverage.py
2+
[run]
3+
branch = True
4+
5+
[report]
6+
# Regexes for lines to exclude from consideration
7+
exclude_lines =
8+
# Have to re-enable the standard pragma
9+
pragma: no cover
10+
11+
# Don't complain about missing debug-only code:
12+
def __repr__
13+
if self\.debug
14+
15+
# Don't complain if tests don't hit defensive assertion code:
16+
raise AssertionError
17+
raise NotImplementedError
18+
19+
# Don't complain if non-runnable code isn't run:
20+
if 0:
21+
if __name__ == .__main__.:
22+
23+
ignore_errors = True
24+
25+
[html]
26+
directory = coverage_html_report

.github/workflows/pytest.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ jobs:
99
strategy:
1010
matrix:
1111
python-version: [3.6, 3.7, 3.8]
12-
fail-fast: false
12+
include:
13+
- python-version: 3.8
14+
code-cov: true
15+
fail-fast: false
1316
max-parallel: 2
1417

1518
steps:
@@ -29,7 +32,7 @@ jobs:
2932
echo "::set-output name=BEFORE::$(git status --porcelain -b)"
3033
- name: Run tests
3134
run: |
32-
if [ ${{ matrix.code-cov }} ]; then codecov='--cov=autoPyTorch --cov-report=xml'; fi
35+
if [ ${{ matrix.code-cov }} ]; then codecov='--cov=autoPyTorch --cov-report=xml --cov-config=.coveragerc'; fi
3336
python -m pytest --forked --durations=20 --timeout=600 --timeout-method=signal -v $codecov test
3437
- name: Check for files left behind by test
3538
if: ${{ always() }}

autoPyTorch/api/base_task.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
STRING_TO_OUTPUT_TYPES,
3535
STRING_TO_TASK_TYPES,
3636
)
37+
from autoPyTorch.data.base_validator import BaseInputValidator
3738
from autoPyTorch.datasets.base_dataset import BaseDataset
3839
from autoPyTorch.datasets.resampling_strategy import CrossValTypes, HoldoutValTypes
3940
from autoPyTorch.ensemble.ensemble_builder import EnsembleBuilderManager
@@ -203,6 +204,8 @@ def __init__(
203204
self._multiprocessing_context = 'fork'
204205
self._dask_client = SingleThreadedClient()
205206

207+
self.InputValidator: Optional[BaseInputValidator] = None
208+
206209
self.search_space_updates = search_space_updates
207210
if search_space_updates is not None:
208211
if not isinstance(self.search_space_updates,
@@ -273,8 +276,8 @@ def get_search_space(self, dataset: BaseDataset = None) -> ConfigurationSpace:
273276
include=self.include_components,
274277
exclude=self.exclude_components,
275278
search_space_updates=self.search_space_updates)
276-
raise Exception("No search space initialised and no dataset passed. "
277-
"Can't create default search space without the dataset")
279+
raise ValueError("No search space initialised and no dataset passed. "
280+
"Can't create default search space without the dataset")
278281

279282
def _get_logger(self, name: str) -> PicklableClientLogger:
280283
"""

autoPyTorch/datasets/base_dataset.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ def __init__(
129129
if len(self.train_tensors) == 2 and self.train_tensors[1] is not None:
130130
self.output_type: str = type_of_target(self.train_tensors[1])
131131

132-
if STRING_TO_OUTPUT_TYPES[self.output_type] in CLASSIFICATION_OUTPUTS:
132+
if (
133+
self.output_type in STRING_TO_OUTPUT_TYPES
134+
and STRING_TO_OUTPUT_TYPES[self.output_type] in CLASSIFICATION_OUTPUTS
135+
):
133136
self.output_shape = len(np.unique(self.train_tensors[1]))
134137
else:
135138
self.output_shape = self.train_tensors[1].shape[-1] if self.train_tensors[1].ndim > 1 else 1

autoPyTorch/datasets/resampling_strategy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ def stratified_k_fold_cross_validation(random_state: np.random.RandomState,
162162
indices: np.ndarray,
163163
**kwargs: Any
164164
) -> List[Tuple[np.ndarray, np.ndarray]]:
165-
cv = StratifiedKFold(n_splits=num_splits, random_state=random_state)
165+
166+
shuffle = kwargs.get('shuffle', True)
167+
cv = StratifiedKFold(n_splits=num_splits, shuffle=shuffle,
168+
random_state=random_state if not shuffle else None)
166169
splits = list(cv.split(indices, kwargs["stratify"]))
167170
return splits
168171

autoPyTorch/datasets/tabular_dataset.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@
2424
)
2525

2626

27-
class Value2Index(object):
28-
def __init__(self, values: list):
29-
assert all(not (pd.isna(v)) for v in values)
30-
self.values = {v: i for i, v in enumerate(values)}
31-
32-
def __getitem__(self, item: Any) -> int:
33-
if pd.isna(item):
34-
return 0
35-
else:
36-
return self.values[item] + 1
37-
38-
3927
class TabularDataset(BaseDataset):
4028
"""
4129
Base class for datasets used in AutoPyTorch

autoPyTorch/search_space/__init__.py

Whitespace-only changes.

autoPyTorch/search_space/search_space.py

Lines changed: 0 additions & 153 deletions
This file was deleted.

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
"codecov",
4949
"pep8",
5050
"mypy",
51-
"openml"
51+
"openml",
52+
"emcee",
53+
"scikit-optimize",
54+
"pyDOE",
5255
],
5356
"examples": [
5457
"matplotlib",

test/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging.handlers
12
import os
23
import re
34
import shutil
@@ -299,6 +300,7 @@ def get_fit_dictionary(X, y, validator, backend):
299300
'metrics_during_training': True,
300301
'split_id': 0,
301302
'backend': backend,
303+
'logger_port': logging.handlers.DEFAULT_TCP_LOGGING_PORT,
302304
}
303305
backend.save_datamanager(datamanager)
304306
return fit_dictionary

0 commit comments

Comments
 (0)