Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions tests/recipes/wrangles/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,30 @@ def test_extract_regex_first(self):
assert df['Output'][0] == ['cotton', 'This is a match']
assert df['Output'][1] == ['red', 'This is a match']

def test_extract_custom_multi_match(self):
"""
Test the output with multiple input columns with the same matches
"""
df = wrangles.recipe.run(
"""
wrangles:
- extract.custom:
input:
- Col1
- Col2
- Col3
output: Output
model_id: 1eddb7e8-1b2b-4a52
""",
dataframe=pd.DataFrame({
'Col1': ['Charizard is a dragon.'],
'Col2': ['Charizard is a pokemon.'],
'Col3': ['Something else about charizard.']
})
)
assert df.iloc[0]['Output'] == ['Charizard']



class TestExtractRegex:
"""
Expand Down
2 changes: 1 addition & 1 deletion wrangles/recipe_wrangles/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def custom(
)

# Concatenate the results into a single column
df[output] = [_format.concatenate([x for x in row if x], ' ') for row in df_temp.values.tolist()]
df[output] = [list(dict.fromkeys(_format.concatenate([x for x in row if x], ' '))) for row in df_temp.values.tolist()]
Comment thread
thomasstvr marked this conversation as resolved.

else:
# Iterate through the inputs, outputs and model_ids
Expand Down