Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ML libraries optional, fix type issues #206

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/run-repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ docker run \
--name eland-test-runner \
--rm \
elastic/eland \
nox -s test-${PYTHON_VERSION}
nox -s lint test-${PYTHON_VERSION}
2 changes: 1 addition & 1 deletion eland/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def __init__(self) -> None:


class RandomScoreFilter(QueryFilter):
def __init__(self, query: QueryFilter, random_state: int) -> None:
def __init__(self, query: BooleanFilter, random_state: int) -> None:
q = MatchAllFilter() if query.empty() else query

seed = {}
Expand Down
22 changes: 11 additions & 11 deletions eland/ml/_model_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import gzip
import json
from abc import ABC
from typing import List, Dict, Any, Optional
from typing import Sequence, Dict, Any, Optional


def add_if_exists(d: Dict[str, Any], k: str, v: Any) -> None:
Expand All @@ -17,9 +17,9 @@ def add_if_exists(d: Dict[str, Any], k: str, v: Any) -> None:
class ModelSerializer(ABC):
def __init__(
self,
feature_names: List[str],
feature_names: Sequence[str],
target_type: Optional[str] = None,
classification_labels: Optional[List[str]] = None,
classification_labels: Optional[Sequence[str]] = None,
):
self._target_type = target_type
self._feature_names = feature_names
Expand All @@ -33,7 +33,7 @@ def to_dict(self) -> Dict[str, Any]:
return d

@property
def feature_names(self) -> List[str]:
def feature_names(self) -> Sequence[str]:
return self._feature_names

def serialize_model(self) -> Dict[str, Any]:
Expand Down Expand Up @@ -84,10 +84,10 @@ def to_dict(self) -> Dict[str, Any]:
class Tree(ModelSerializer):
def __init__(
self,
feature_names: List[str],
feature_names: Sequence[str],
target_type: Optional[str] = None,
tree_structure: Optional[List[TreeNode]] = None,
classification_labels: Optional[List[str]] = None,
tree_structure: Optional[Sequence[TreeNode]] = None,
classification_labels: Optional[Sequence[str]] = None,
):
super().__init__(
feature_names=feature_names,
Expand All @@ -107,12 +107,12 @@ def to_dict(self) -> Dict[str, Any]:
class Ensemble(ModelSerializer):
def __init__(
self,
feature_names: List[str],
trained_models: List[ModelSerializer],
feature_names: Sequence[str],
trained_models: Sequence[ModelSerializer],
output_aggregator: Dict[str, Any],
target_type: Optional[str] = None,
classification_labels: Optional[List[str]] = None,
classification_weights: Optional[List[float]] = None,
classification_labels: Optional[Sequence[str]] = None,
classification_weights: Optional[Sequence[float]] = None,
):
super().__init__(
feature_names=feature_names,
Expand Down