Skip to content

Bug fix column list transform input #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions pkg/workloads/spark_job/spark_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,30 +206,41 @@ def validate_transformers(spark, ctx, features_to_transform, raw_df):
resource_list = sorted(
[ctx.tf_id_map[f] for f in features_to_transform], key=lambda r: r["name"]
)
for transform_resource in resource_list:
ctx.upload_resource_status_start(transform_resource)
for transformed_feature in resource_list:
ctx.upload_resource_status_start(transformed_feature)
try:
tf_name = transform_resource["name"]
input_features_dict = transformed_feature["inputs"]["features"]

input_cols = []

for k in sorted(input_features_dict.keys()):
if util.is_list(input_features_dict[k]):
input_cols += sorted(input_features_dict[k])
else:
input_cols.append(input_features_dict[k])

tf_name = transformed_feature["name"]
logger.info("Transforming {} to {}".format(", ".join(input_cols), tf_name))

spark_util.validate_transformer(tf_name, test_df, ctx, spark)
sample_df = spark_util.transform_feature(
transform_resource["name"], sample_df, ctx, spark
transformed_feature["name"], sample_df, ctx, spark
)

sample_df.select(tf_name).collect() # run the transformer
show_df(sample_df.select(*input_cols, tf_name), ctx, n=3, sort=False)

for alias in transform_resource["aliases"]:
input_cols = sorted(transform_resource["inputs"]["features"].values())
for alias in transformed_feature["aliases"][1:]:
logger.info("Transforming {} to {}".format(", ".join(input_cols), alias))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of an edge case, and it actually isn't possible until we allow chained transformations, but in theory there could be an alias transformed feature that uses aliased features as inputs, so it might be worth it to re-generate the names of the input cols. You could make a helper in context.py that does this and call it twice here (once for the actual transformation, and once for each additional alias). But since right now we don't have chained transformations and raw feature aliases are not allowed, it actually isn't an issue at the moment, so we can address this in the future when we add chained transformations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea definitely a case that we need to look out for, good point.


select_cols = input_cols + [alias]
display_transform_df = sample_df.withColumn(alias, F.col(tf_name)).select(
*select_cols
*input_cols, alias
)
show_df(display_transform_df, ctx, n=3, sort=False)
except:
ctx.upload_resource_status_failed(transform_resource)
ctx.upload_resource_status_failed(transformed_feature)
raise
ctx.upload_resource_status_success(transform_resource)
ctx.upload_resource_status_success(transformed_feature)


def create_training_datasets(spark, ctx, training_datasets, accumulated_df):
Expand Down