Charles Lariviere
04/11/2022, 2:01 PMroot_input_manager
, specifically getting the config schema to generate default values.
Given this root input manager:
@root_input_manager(
input_config_schema={
"filepath": Field(str, is_required=True),
"sep": Field(str, default_value=",", is_required=False, description="Delimiter to use."),
}
)
def csv_to_df(context):
return pd.read_csv(
context.config["filepath"],
sep=context.config.get("sep")
)
And a test that looks like this:
def test_csv_to_df(self):
manager = csv_to_df(None)
context = build_input_context(
config={"filepath": os.path.join(self.fixtures_dir, "csv_to_df.csv")}
)
df = manager.load_input(context)
...
The sep
config value remains None
— the default_value
defined in the Field
object does not seem to get compiled. I’m assuming it’s because passing the config
argument in build_input_context
overrides whatever method compiles the schema, but I haven’t been successful in finding a workaround.
Am I missing something, or is it simply not yet supported given it’s still experimental?sandy
04/11/2022, 3:57 PM@root_input_manager(
input_config_schema={
"filepath": Field(str, is_required=True),
"sep": Field(str, is_required=False, description="Delimiter to use."),
}
)
def csv_to_df(context):
return pd.read_csv(
context.config["filepath"],
sep=context.config.get("sep", ",")
)
Charles Lariviere
04/11/2022, 4:33 PM