Skip to content

Commit

Permalink
Added row filter value conversion to column dtype.
Browse files Browse the repository at this point in the history
  • Loading branch information
pineapple-cat committed Oct 12, 2023
1 parent f64b2b8 commit 1a9f360
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions post-processing/post_processing.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import argparse
import ast
import errno
import math
import operator as op
import os
import re
import traceback
import math
from functools import reduce
from itertools import chain
from pathlib import Path
Expand Down Expand Up @@ -278,9 +278,10 @@ def row_filter(self, filter, df: pd.DataFrame):
mask = df[column].isnull() if operator == op.eq else df[column].notnull()
else:
try:
# FIXME: try to interpret the comparison value as whatever type the df column is
# interpret comparison value as column dtype
value = pd.Series(value, dtype=df[column].dtype).iloc[0]
mask = operator(df[column], value)
except TypeError as e:
except TypeError or ValueError as e:
e.args = (e.args[0] + " for column: \'{0}\' and value: \'{1}\'".format(column, value),)
raise

Expand Down
4 changes: 2 additions & 2 deletions post-processing/test_post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ def test_high_level_script(run_sombrero):

# check expected failure from invalid filter value type
try:
post_.run_post_processing(sombrero_log_path, {"filters": [["flops_value", ">", "1"]], "series": [], "x_axis": {"value": "tasks", "units": {"custom": None}}, "y_axis": {"value": "flops_value", "units": {"column": "flops_unit"}}, "column_types": {"tasks": "int", "flops_value": "float", "flops_unit": "str"}})
except TypeError:
post_.run_post_processing(sombrero_log_path, {"filters": [["flops_value", ">", "v"]], "series": [], "x_axis": {"value": "tasks", "units": {"custom": None}}, "y_axis": {"value": "flops_value", "units": {"column": "flops_unit"}}, "column_types": {"tasks": "int", "flops_value": "float", "flops_unit": "str"}})
except ValueError:
assert True
else:
assert False
Expand Down

0 comments on commit 1a9f360

Please sign in to comment.