Skip to main content

Compute Wrangles

Compute wrangles, with recipe examples, parameters, and behavior.

Case When​

Assign values to a column based on conditional logic.

Parameters​

NameDescriptionAccepted ValuesDefaultRequired
I/O
outputName of the output column.string—Yes
Options
casesList of conditions and corresponding values.array—Yes
defaultValue to assign if no conditions are met. Default None.string, number, integer, boolean, nullnullNo
Conditions
ifCondition that determines whether the wrangle runs as a whole. Recipe variables may be referenced with ${variable}.string—No
whereFilter rows before applying the wrangle using SQL-like criteria, such as column1 = 123 OR column2 = 'abc'.string—No
where_paramsValues used with where for parameterized criteria. Uses SQLite placeholder syntax such as ? or :name.array, object—No

Examples​

wrangles:
- compute.case_when:
output: Letter Grade
cases:
- condition: Grade > 89
value: 'A'
- condition: 90 > Grade > 79
value: 'B'
- condition: 80 > Grade > 69
value: 'C'
- condition: 70 > Grade
value: 'F'
StudentGrade
Billy62
Sarah91
Timmy88
Tammy74
Letter Grade
F
A
B
C

Conditions can be combined so multiple criteria must be met before assigning a value.

wrangles:
- compute.case_when:
output: Letter Grade
cases:
- condition: (Grade > .89) & (Attendance == 'Good')
value: 'A'
- condition: (.90 > Grade > .79) & (Attendance == 'Good')
value: 'B'
- condition: (.80 > Grade > .69) & (Attendance == 'Good')
value: 'C'
- condition: (.70 > Grade) or (Attendance == 'Poor')
value: 'F'
StudentGradeAttendance
Billy62Poor
Sarah91Poor
Timmy88Good
Tammy74Good
Letter Grade
F
F
B
C
Access
RequirementValue
AI-poweredNo
Requires WrangleWorks accountNo
Requires subscriptionNo
Requires external API keyNo
Technical details
FieldValue
Catalog ID3
Catalog keycompute.case_when
Recipe keycompute.case_when
Catalog statusactive
Lifecycle statusactive
Recipe Writer eligibleYes
Namespacecompute
Documentation groupcompute
AliasesNone
Runtime symbolwrangles.recipe_wrangles.compute.case_when
Legacy UUID9a9662e4-53d1-4932-8adf-bc3e7aa364ad

Sources


Score Search Results​

Scores and filters search results based on progressive partial/exact matching. Can return dictionaries or a parallel list of formatted strings.

Parameters​

NameDescriptionAccepted ValuesDefaultRequired
I/O
inputList of 3 to 5 columns -> [results, suppliers, part_codes, mpns (optional), descriptions (optional)].array—Yes
outputOutput column for the dictionaries. If a list of 2 is provided, outputs [dicts_column, pretty_strings_column].string, array—Yes
Options
must_match_part_codeIf true, filters out results that don't satisfy the allowed match types.booleantrueNo
allow_mpn_exactTreat exact MPN matches as valid part code matches.booleantrueNo
allow_mpn_partialTreat partial MPN matches as valid part code matches.booleantrueNo
allow_other_exactTreat exact other part code matches as valid part code matches.booleantrueNo
allow_other_partialTreat partial other part code matches as valid part code matches.booleantrueNo
blacklist_keywordsComma-separated list or array of keywords to filter out URLs containing them.string""No
mpn_exact_scoreMpn Exact Score value accepted by the runtime.number8No
mpn_partial_baseMpn Partial Base value accepted by the runtime.number4No
part_code_exact_scorePart Code Exact Score value accepted by the runtime.number6No
part_code_partial_basePart Code Partial Base value accepted by the runtime.number2No
supplier_exact_scoreSupplier Exact Score value accepted by the runtime.number3No
supplier_partial_baseSupplier Partial Base value accepted by the runtime.number1No
context_match_baseContext Match Base value accepted by the runtime.number2No
fuzzy_match_thresholdFuzzy Match Threshold value accepted by the runtime.number0.8No
Conditions
ifCondition that determines whether the wrangle runs as a whole. Recipe variables may be referenced with ${variable}.string—No
whereFilter rows before applying the wrangle using SQL-like criteria, such as column1 = 123 OR column2 = 'abc'.string—No
where_paramsValues used with where for parameterized criteria. Uses SQLite placeholder syntax such as ? or :name.array, object—No

Examples​

This template scores search results using supplier and part-code context. The fields added to each result dictionary depend on the scoring configuration.

wrangles:
- compute.score_search_results:
input:
- Search Results
- Suppliers
- Part Codes
output:
- Scored Results
allow_other_exact: true
must_match_part_code: true
Search ResultsSuppliersPart Codes
[{"title": "SKF 6202 bearing", "link": "https://example.com/6202"}]["SKF"]["6202"]
Scored Results
Ranked result dictionaries

Template based on the documented parameters; no published source example is currently available.

Access
RequirementValue
AI-poweredNo
Requires WrangleWorks accountNo
Requires subscriptionNo
Requires external API keyNo
Technical details
FieldValue
Catalog ID4
Catalog keycompute.score_search_results
Recipe keycompute.score_search_results
Catalog statusactive
Lifecycle statusactive
Recipe Writer eligibleYes
Namespacecompute
Documentation groupcompute
AliasesNone
Runtime symbolwrangles.recipe_wrangles.compute.score_search_results
Legacy UUID313a8ec0-cf13-4956-8d3b-5362b8641d0f

Sources


Math​

Apply a mathematical calculation.

Apply mathematical calculations to columns. Also called as maths.

info

Spaces within column headers are replaced with underscores automatically. Account for this when writing expressions in input.

Parameters​

NameDescriptionAccepted ValuesDefaultRequired
I/O
inputThe mathematical expression using column names. e.g. column1 * column2 + column3. Note: spaces within column names are replaced by underscores (_).string—Yes
outputThe column to output the results to.string—Yes
Conditions
ifCondition that determines whether the wrangle runs as a whole. Recipe variables may be referenced with ${variable}.string—No
whereFilter rows before applying the wrangle using SQL-like criteria, such as column1 = 123 OR column2 = 'abc'.string—No
where_paramsValues used with where for parameterized criteria. Uses SQLite placeholder syntax such as ? or :name.array, object—No

Examples​

wrangles:
- math:
input: sqrt(Values)
output: Square Root
Values
4
9
16
Square Root
2
3
4
Access
RequirementValue
AI-poweredNo
Requires WrangleWorks accountNo
Requires subscriptionNo
Requires external API keyNo
Technical details
FieldValue
Catalog ID82
Catalog keymath
Recipe keymath
Catalog statusactive
Lifecycle statusactive
Recipe Writer eligibleYes
NamespaceRoot-level
Documentation groupcompute
AliasesNone
Runtime symbolwrangles.recipe_wrangles.main.math
Legacy UUID494b11ad-00c1-4748-8b93-6bec982f4fec

Sources


Python​

Apply a simple single-line python command. For more complex python use a custom function. Note, this evaluates the python command - be especially cautious including variables from untrusted sources within the command string. The python command will be evaluated once for each row and the result returned. Reference column values by using their name. Non-alphanumeric characters within column names are replaced by underscores (_) Additionally, all columns are available as a dict named kwargs. Additional parameters set for the wrangle will also be available to the command.

The Python wrangle executes simple Python commands inline within a recipe. Row values are referenced by column name and commands are evaluated once per row. Spaces within column names are replaced by underscores (_). All columns are also available as a dictionary named kwargs. For more complex Python, use custom functions.

caution

This wrangle evaluates the Python command. Be cautious when including variables from untrusted sources in the command string.

Parameters​

NameDescriptionAccepted ValuesDefaultRequired
I/O
outputName or list of output column(s). To output multiple columns, return a list of the corresponding length.string, array—Yes
inputName or list of input column(s) to filter the data available to the command. Useful in conjunction with kwargs to target a variable range of columns. If not specified, all columns will be available.string, integer, array, nullnullNo
Options
commandPython command. This must return a value. Note: any non-alphanumeric characters in variable names are replaced by underscores (_).string—Yes
Conditions
ifCondition that determines whether the wrangle runs as a whole. Recipe variables may be referenced with ${variable}.string—No
whereFilter rows before applying the wrangle using SQL-like criteria, such as column1 = 123 OR column2 = 'abc'.string—No
where_paramsValues used with where for parameterized criteria. Uses SQLite placeholder syntax such as ? or :name.array, object—No
Errors
exceptValue to return for the row if an exception occurs during the evaluation. If not provided, an exception will be raised as normal. If multiple output columns are specified, this must match the length.string, array, number, integer, boolean, object—No

Examples​

wrangles:
- python:
output: result
command: My_Column.upper()
My Column
example text
result
EXAMPLE TEXT

The Python wrangle supports parameters so values of unknown origin can be injected safely.

wrangles:
- python:
output: sliced
command: input_column[:i]
i: ${var}

No sample available.

No sample available.

Access
RequirementValue
AI-poweredNo
Requires WrangleWorks accountNo
Requires subscriptionNo
Requires external API keyNo
Technical details
FieldValue
Catalog ID85
Catalog keypython
Recipe keypython
Catalog statusactive
Lifecycle statusactive
Recipe Writer eligibleYes
NamespaceRoot-level
Documentation groupcompute
AliasesNone
Runtime symbolwrangles.recipe_wrangles.main.python
Legacy UUIDc0398a11-7731-4e47-8df0-b07eea0b1d6c

Sources


SQL​

Apply a SQL command to the current dataframe. Only SELECT statements are supported - the result will be the output.

Apply a SQL command to the current dataframe. Only SELECT statements are supported; the result becomes the output. The current table is called df.

info

SQL does not currently work with objects. If your table contains objects, use convert.to_json before using SQL. SQL is not compatible with where filtering.

Parameters​

NameDescriptionAccepted ValuesDefaultRequired
Options
commandSQL Command. The table is called df. For specific SQL syntax, this uses the SQLite dialect.string—Yes
paramsVariables to use in conjunctions with query. This allows the query to be parameterized. This uses sqlite syntax (? or :name).array, object, nullnullNo
preserve_data_typesPreserve Data Types value accepted by the runtime.booleantrueNo
Formatting
preserve_indexPreserve Index value accepted by the runtime.booleanfalseNo
Conditions
ifCondition that determines whether the wrangle runs as a whole. Recipe variables may be referenced with ${variable}.string—No
whereFilter rows before applying the wrangle using SQL-like criteria, such as column1 = 123 OR column2 = 'abc'.string—No
where_paramsValues used with where for parameterized criteria. Uses SQLite placeholder syntax such as ? or :name.array, object—No

Examples​

wrangles:
- sql:
command: |
SELECT header1, header2
FROM df
WHERE header1 >= 2
header1header2header3
1ax
2by
3cz
header1header2
2b
3c
Access
RequirementValue
AI-poweredNo
Requires WrangleWorks accountNo
Requires subscriptionNo
Requires external API keyNo
Technical details
FieldValue
Catalog ID94
Catalog keysql
Recipe keysql
Catalog statusactive
Lifecycle statusactive
Recipe Writer eligibleYes
NamespaceRoot-level
Documentation groupcompute
AliasesNone
Runtime symbolwrangles.recipe_wrangles.main.sql
Legacy UUID467a06b1-a697-4d31-8061-7d83a719fd79

Sources


Maths (Deprecated)​

Deprecated

This compatibility wrangle remains available for existing recipes. Use math for new recipes.

Deprecated alias for math; evaluate an expression and write its result to an output column.

Behavior​

Deprecated alias for math; evaluate an expression and write its result to an output column.

This guidance was derived from the callable signature.

Parameters​

NameDescriptionAccepted ValuesDefaultRequired
I/O
inputName, index, or list of input columns.string—Yes
outputName or list of output columns.string—Yes
Conditions
ifCondition that determines whether the wrangle runs as a whole. Recipe variables may be referenced with ${variable}.string—No
whereFilter rows before applying the wrangle using SQL-like criteria, such as column1 = 123 OR column2 = 'abc'.string—No
where_paramsValues used with where for parameterized criteria. Uses SQLite placeholder syntax such as ? or :name.array, object—No
Access
RequirementValue
AI-poweredNo
Requires WrangleWorks accountNo
Requires subscriptionNo
Requires external API keyNo
Technical details
FieldValue
Catalog ID83
Catalog keymaths
Recipe keymaths
Catalog statusactive
Lifecycle statusdeprecated
Recipe Writer eligibleNo
Recipe Writer exclusionDeprecated compatibility key; use math.
Replaced bymath
NamespaceRoot-level
Documentation groupcompute
AliasesNone
Runtime symbolwrangles.recipe_wrangles.main.maths
Legacy UUIDNone

Sources