Skip to content

Commit

Permalink
update dataframe_transformer: adjust parameters
Browse files Browse the repository at this point in the history
Signed-off-by: mgqa34 <mgq3374541@163.com>
  • Loading branch information
mgqa34 committed Jun 16, 2023
1 parent 1673108 commit d80570a
Showing 1 changed file with 21 additions and 46 deletions.
67 changes: 21 additions & 46 deletions python/fate/components/components/dataframe_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,42 @@
@cpn.component(roles=[LOCAL])
@cpn.table_input("table", roles=[LOCAL])
@cpn.dataframe_output("dataframe_output", roles=[LOCAL])
@cpn.parameter("sample_id_name", type=str, default=None, optional=True)
@cpn.parameter("match_id_name", type=str, default=None, optional=True)
@cpn.parameter("match_id_list", type=List[str], default=None, optional=True)
@cpn.parameter("match_id_range", type=int, default=1, optional=True)
@cpn.parameter("label_name", type=str, default=None, optional=True)
@cpn.parameter("label_type", type=str, default="int32", optional=True)
@cpn.parameter("weight_name", type=str, default=None, optional=True)
@cpn.parameter("weight_type", type=str, default="float32", optional=True)
@cpn.parameter("header", type=str, default=None, optional=False)
@cpn.parameter("na_values", type=Union[str, list, dict], default=None, optional=True)
@cpn.parameter("dtype", type=Union[Dict, str], default="float32", optional=True)
@cpn.parameter("namespace", type=str, default=",", optional=True)
@cpn.parameter("name", type=str, default="dense", optional=True)
@cpn.parameter("anonymous_role", type=str, default=None, optional=True)
@cpn.parameter("anonymous_party_id", type=str, default=None, optional=True)
@cpn.parameter("delimiter", type=str, default=",", optional=True)
@cpn.parameter("input_format", type=str, default="dense", optional=True)
@cpn.parameter("tag_with_value", type=bool, default=False, optional=True)
@cpn.parameter("tag_value_delimiter", type=str, default=":", optional=True)
def dataframe_transformer(
ctx,
role: Role,
table,
dataframe_output,
sample_id_name,
match_id_name,
match_id_list,
match_id_range,
label_name,
label_type,
weight_name,
weight_type,
header,
na_values,
dtype,
namespace,
name,
anonymous_role,
anonymous_party_id,
delimiter,
input_format,
tag_with_value,
tag_value_delimiter
):
from fate.arch.dataframe import TableReader

metadata = table.schema["meta"]
table_reader = TableReader(
sample_id_name=sample_id_name,
match_id_name=match_id_name,
match_id_list=match_id_list,
match_id_range=match_id_range,
label_name=label_name,
label_type=label_type,
weight_name=weight_name,
weight_type=weight_type,
header=header,
na_values=na_values,
dtype=dtype,
sample_id_name=metadata.get("sample_id_name", None),
match_id_name=metadata.get("match_id_name", None),
match_id_list=metadata.get("match_id_list", None),
match_id_range=metadata.get("match_id_range", 1),
label_name=metadata.get("label_name", None),
label_type=metadata.get("label_type", "int32"),
weight_name=metadata.get("weight_name", None),
weight_type=metadata.get("weight_type", "float32"),
header=metadata.get("header", None),
na_values=metadata.get("na_values", None),
dtype=metadata.get("dtype", "float32"),
anonymous_role=anonymous_role,
anonymous_party_id=anonymous_party_id,
delimiter=delimiter,
input_format=input_format,
tag_with_value=tag_with_value,
tag_value_delimiter=tag_value_delimiter
delimiter=metadata.get("delimiter", ","),
input_format=metadata.get("input_format", "dense"),
tag_with_value=metadata.get("tag_with_value", False),
tag_value_delimiter=metadata.get("tag_value_delimiter", ":")
)

df = table_reader.to_frame(ctx, table)
ctx.writer(dataframe_output).write_dataframe(df)
ctx.writer(dataframe_output).write(df, namespace=namespace, name=name)

0 comments on commit d80570a

Please sign in to comment.