This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GitSource(FlexibleModel): | |
git_url: str | |
git_provider: str | |
git_branch: Optional[str] | |
git_tag: Optional[str] | |
git_commit: Optional[str] | |
@root_validator(pre=True) | |
def _validate(cls, values): # noqa | |
at_least_one_of(["git_branch", "git_tag", "git_commit"], values) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mutually_exclusive(fields_names: List[str], values: Dict[str, Any]): | |
non_empty_values = [key for key, item in values.items() if item] # will coalesce both checks for None and [] | |
_matching_fields = [f for f in fields_names if f in non_empty_values] | |
if len(_matching_fields) > 1: | |
raise ValueError( | |
f""" | |
The following fields {_matching_fields} are mutually exclusive. | |
Provided payload: {values} | |
""", | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseNameMixin(BaseModel): | |
_only_one_provided = root_validator(pre=True, allow_reuse=True)( | |
lambda _, values: at_least_one_by_suffix("_name", values) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseTaskMixin(BaseModel): | |
_only_one_provided = root_validator(pre=True, allow_reuse=True)( | |
lambda _, values: at_least_one_by_suffix("_task", values) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def at_least_one_by_suffix(suffix: str, values: Dict[str, Any]): | |
_matching_fields = [f for f in values if f.endswith(suffix)] | |
if not _matching_fields: | |
raise ValueError( | |
f""" | |
At least one field with suffix {suffix} should be provided. | |
Provided payload: {values} | |
""", | |
) | |
return values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
resp = requests.get("https://reqres.in/api/users").json() | |
required_value = [o for o in resp["data"] if o["some_property"] == "something"][0] | |
nest_prop = required_value.get("some_nested_property") | |
if nest_prop["something"]: | |
do_something() | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
resp = requests.get("https://some/api/endpoint").json() | |
required_value = [o for o in resp if o["some_property"] == "something"] | |
if required_value["some_other_property"]: | |
do_something() | |
else: | |
do_something_else() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Custom section is used to store configurations that might be repetative. | |
# Please read YAML documentation for details on how to use substitutions and anchors. | |
custom: | |
basic-cluster-props: &basic-cluster-props | |
spark_version: "11.1.x-cpu-ml-scala2.12" | |
basic-static-cluster: &basic-static-cluster | |
<<: *basic-cluster-props | |
instance_pool_name: "f8s-v2-pool" | |
driver_instance_pool_name: "f8s-v2-pool" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_trainer_trials( | |
spark: SparkSession, dataset_fixture: pd.DataFrame, mlflow_local: MlflowInfo | |
): | |
model_data = Provider.get_data( | |
dataset_fixture, SourceMetadata(version=0, database="db", table="table") | |
) | |
def custom_search_space(): | |
search_space = { | |
"classifier": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Trainer: | |
# omitted for readability | |
def _train_model_and_log_results( | |
self, parameters: SearchSpace | |
) -> Tuple[Dict[str, Any], Pipeline]: | |
pipeline = Provider.get_pipeline(parameters) | |
pipeline.fit(self.data.train.X, self.data.train.y) |
NewerOlder