Neuron allows us to use the if
function to filter out data points that don't meet a condition. The if
function evaluates a condition and returns values for true
and false
results.
You can use the none
constant as an output for one case of an if
function to discard the data point for that case.
To filter out data points that match a condition
Create a transform that uses the if
function to define a condition that checks if a condition is met, and returns result_if_true
when the condition is actually met and returns result_if_false
with a value of none
when the condition is missed or not met.
Example: Filter out data points where water isn't boiling
Consider a scenario where you have a measurement, temp
, that provides the temperature (in Celsius) of water in a machine. You can define the following transform to filter out data points where the water isn't boiling:
Transform:
boiling_temps = if(gte(temp, 100), temp, none)
– Returns the temperature if it's greater than or equal to 100 degrees Celsius, otherwise returns no data point.
We recommend that you use UFCS (Uniform Function Call Syntax) for nested conditional functions where one or more arguments are conditional functions.
You must use elif(condition, result_if_true, result_if_false)
with UFCS.