Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Fixed serialization to always explicitly output single pipeline. Reso…
Browse files Browse the repository at this point in the history
…lves issue #2
  • Loading branch information
alexrallen committed Nov 30, 2018
1 parent 5777789 commit d69197a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
11 changes: 6 additions & 5 deletions foreshadow/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ def _map_pipelines(self):
if len(v.multi_pipeline) > 0
else [("null", None)]
),
"single": Pipeline(
deepcopy(v.single_pipeline)
if len(v.single_pipeline) > 0
else [("null", None)]
),
# Extract multi pipeline from JSON config (highest priority)
**{k: v for k, v in self._intent_pipelines.get(v.__name__, {}).items()},
}
Expand Down Expand Up @@ -350,11 +355,7 @@ def serialize(self):

# Serialize intent multi processors
json_intents = {
k: {
l: serialize_pipeline(j)
for l, j in v.items()
if j.steps[0][PipelineStep["NAME"]] != "null"
}
k: {l: serialize_pipeline(j) for l, j in v.items()}
for k, v in self._intent_pipelines.items()
}

Expand Down
2 changes: 1 addition & 1 deletion foreshadow/tests/test_configs/test_serialize.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"columns": {"crim": ["TestGenericIntent", [["StandardScaler", "Scaler", {"copy": true, "keep_columns": false, "name": "Scaler", "with_mean": false, "with_std": true}]], ["TestGenericIntent", "TestNumericIntent"]], "zn": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "indus": ["TestGenericIntent", [], ["TestGenericIntent", "TestNumericIntent"]], "chas": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "nox": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "rm": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "age": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "dis": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "rad": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "tax": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "ptratio": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "b": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "lstat": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "medv": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]]}, "postprocess": [["pca", ["age"], [["PCA", "PCA", {"copy": true, "iterated_power": "auto", "keep_columns": false, "n_components": 2, "name": "PCA", "random_state": null, "svd_solver": "auto", "tol": 0.0, "whiten": false}]]]], "intents": {"TestGenericIntent": {"multi": [["PCA", "pca", {"copy": true, "iterated_power": "auto", "keep_columns": false, "n_components": 2, "name": "pca", "random_state": null, "svd_solver": "auto", "tol": 0.0, "whiten": false}]]}, "TestNumericIntent": {"multi": [["PCA", "pca", {"copy": true, "iterated_power": "auto", "keep_columns": false, "n_components": 5, "name": "pca", "random_state": null, "svd_solver": "auto", "tol": 0.0, "whiten": false}]], "single": [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]]}}}
{"columns": {"crim": ["TestGenericIntent", [["StandardScaler", "Scaler", {"copy": true, "keep_columns": false, "name": "Scaler", "with_mean": false, "with_std": true}]], ["TestGenericIntent", "TestNumericIntent"]], "zn": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "indus": ["TestGenericIntent", [], ["TestGenericIntent", "TestNumericIntent"]], "chas": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "nox": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "rm": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "age": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "dis": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "rad": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "tax": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "ptratio": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "b": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "lstat": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]], "medv": ["TestNumericIntent", [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]], ["TestGenericIntent", "TestNumericIntent"]]}, "postprocess": [["pca", ["age"], [["PCA", "PCA", {"copy": true, "iterated_power": "auto", "keep_columns": false, "n_components": 2, "name": "PCA", "random_state": null, "svd_solver": "auto", "tol": 0.0, "whiten": false}]]]], "intents": {"TestGenericIntent": {"multi": [["PCA", "pca", {"copy": true, "iterated_power": "auto", "keep_columns": false, "n_components": 2, "name": "pca", "random_state": null, "svd_solver": "auto", "tol": 0.0, "whiten": false}]], "single": []}, "TestNumericIntent": {"multi": [["PCA", "pca", {"copy": true, "iterated_power": "auto", "keep_columns": false, "n_components": 5, "name": "pca", "random_state": null, "svd_solver": "auto", "tol": 0.0, "whiten": false}]], "single": [["Imputer", "impute", {"axis": 0, "copy": true, "keep_columns": false, "missing_values": "NaN", "name": "impute", "strategy": "mean", "verbose": 0}]]}}}
3 changes: 0 additions & 3 deletions foreshadow/tests/test_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,4 @@ def test_preprocessor_serialize():
proc.fit(df)
out = proc.serialize()

print(json.dumps(truth))
print(json.dumps(out))

assert json.loads(json.dumps(truth)) == json.loads(json.dumps(out))

0 comments on commit d69197a

Please sign in to comment.