Skip to content

Commit 47b931c

Browse files
committed
Shows how to use validator without reaching into driver
1 parent e451d28 commit 47b931c

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

examples/schema/dataflow.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ def df_with_renamed_cols(df_with_new_cols: pd.DataFrame) -> pd.DataFrame:
3131
from hamilton import driver
3232
from hamilton.plugins import h_schema
3333

34-
dr = (
35-
driver.Builder()
36-
.with_modules(__main__)
37-
.with_adapters(h_schema.SchemaValidator("./schemas"))
38-
.build()
39-
)
34+
validator_adapter = h_schema.SchemaValidator("./schemas")
35+
dr = driver.Builder().with_modules(__main__).with_adapters(validator_adapter).build()
4036
res = dr.execute(["df_with_renamed_cols"])
41-
print(json.dumps(dr.adapter.adapters[0].json_schemas, indent=2))
37+
print(json.dumps(validator_adapter.json_schemas, indent=2))

examples/schema/multi_dataflow.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ def pandas_new_col__v4(ibis_rename: ir.Table) -> pd.DataFrame:
6161
"--no-check", action="store_false", help="Disable `check` to update the stored schemas."
6262
)
6363
args = parser.parse_args()
64-
64+
validator_adapter = h_schema.SchemaValidator(
65+
"./multi_schemas", check=args.no_check, importance="warn"
66+
)
6567
dr = (
6668
driver.Builder()
6769
.with_modules(__main__)
6870
.with_config(dict(version=args.version))
69-
.with_adapters(
70-
h_schema.SchemaValidator("./multi_schemas", check=args.no_check, importance="warn")
71-
)
71+
.with_adapters(validator_adapter)
7272
.build()
7373
)
7474
res = dr.execute(["pandas_new_col"])
7575
print(res["pandas_new_col"].head())
7676
print()
7777

78-
print(json.dumps(dr.adapter.adapters[0].json_schemas, indent=2))
78+
print(json.dumps(validator_adapter.json_schemas, indent=2))

0 commit comments

Comments
 (0)