Filters the data based on the provided conditions.
:param conditions: Dictionary containing the conditions for filtering. The keys should be the names of the data fields, and the values should be callables or expressions that return a boolean mask.
:return: Dictionary containing the filtered data.
:param conditions: List of conditions as strings for filtering. The keys should be the names of the data fields, and the conditions should be in a format that can be split into key, operator, and value.
:return: Instance of the class containing the filtered data.
"""
filteredData=self.data.copy()
mask=np.ones(len(next(iter(self.data.values()))),dtype=bool)# Initial mask allowing all elements
mask=np.ones(len(next(iter(self.data.values()))),dtype=bool)# Initial mask allowing all elements
# Applying the conditions to create the mask
forconditioninconditions:
key,op,value=condition.split()
comparison_value=float(value)
field_values=self.data[key].astype(float)
# Determine the correct comparison to apply
operation={
'==':np.equal,
'<':np.less,
'>':np.greater,
'<=':np.less_equal,
'>=':np.greater_equal,
}.get(op)
ifoperationisNone:
raiseValueError(f"Invalid operator {op}")
mask&=operation(field_values,comparison_value)
key,op,value=condition.split(None,2)# Split by the first two spaces only