Skip to content

Commit f55db54

Browse files
authored
Late import sklearn and remove test parallelism (#333)
* SKLearn was slowing start up for everything. Move it to late import * Remove parallelism
1 parent 13421b0 commit f55db54

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
mkdir test_results
6161
set -e
6262
TEST_FILES=$(circleci tests glob "tests/**/test_*.py" | circleci tests split --split-by=timings)
63-
poetry run coverage run --include=nucleus/* -m pytest -n 6 -s -v --junitxml=test_results/junit.xml $TEST_FILES
63+
poetry run coverage run --include=nucleus/* -m pytest -s -v --junitxml=test_results/junit.xml $TEST_FILES
6464
poetry run coverage report
6565
poetry run coverage html
6666
- store_test_results:

nucleus/metrics/categorization_metrics.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
from dataclasses import dataclass
33
from typing import List, Optional, Set, Tuple, Union
44

5-
from sklearn.metrics import f1_score
6-
75
from nucleus.annotation import AnnotationList, CategoryAnnotation
86
from nucleus.metrics.base import Metric, MetricResult, ScalarResult
97
from nucleus.metrics.filtering import ListOfAndFilters, ListOfOrAndFilters
@@ -35,6 +33,9 @@ class CategorizationResult(MetricResult):
3533

3634
@property
3735
def value(self):
36+
# late import to avoid slow CLI init
37+
from sklearn.metrics import f1_score
38+
3839
annotation_labels = to_taxonomy_labels(self.annotations)
3940
prediction_labels = to_taxonomy_labels(self.predictions)
4041

@@ -245,6 +246,9 @@ def eval(
245246
)
246247

247248
def aggregate_score(self, results: List[CategorizationResult]) -> ScalarResult: # type: ignore[override]
249+
# late import to avoid slow CLI init
250+
from sklearn.metrics import f1_score
251+
248252
gt = []
249253
predicted = []
250254
for result in results:

0 commit comments

Comments
 (0)