Skip to content

Commit

Permalink
Skip transformation of partition if partition is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchtr committed Mar 18, 2024
1 parent c569c49 commit 442501c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/fondant/component/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,18 +492,19 @@ def wrap_transform(
"""

def wrapped_transform(dataframe: pd.DataFrame) -> pd.DataFrame:
# Call transform method
# Columns of operation specification
columns = [
name for name, field in operation_spec.operation_produces.items()
]

if dataframe.empty:
logger.info("Received empty partition, skipping transformation.")
return dataframe
return pd.DataFrame(columns=columns)

# Call transform method
dataframe = transform(dataframe)

# Drop columns not in specification
columns = [
name for name, field in operation_spec.operation_produces.items()
]

return dataframe[columns]

return wrapped_transform
Expand Down
3 changes: 2 additions & 1 deletion tests/component/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,5 +617,6 @@ def transform(dataframe: pd.DataFrame) -> pd.DataFrame:
),
),
)

output_df = wrapped_transform(input_df)
assert input_df.equals(output_df)
assert output_df.equals(pd.DataFrame())

0 comments on commit 442501c

Please sign in to comment.