Skip to content

Commit b2af525

Browse files
committed
Use try-except in preprocessing stage
1 parent 8633e09 commit b2af525

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

pointblank/validate.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9161,37 +9161,47 @@ def interrogate(
91619161

91629162
# Determine whether any preprocessing functions are to be applied to the table
91639163
if validation.pre is not None:
9164-
# Read the text of the preprocessing function
9165-
pre_text = _pre_processing_funcs_to_str(validation.pre)
9164+
try:
9165+
# Read the text of the preprocessing function
9166+
pre_text = _pre_processing_funcs_to_str(validation.pre)
91669167

9167-
# Determine if the preprocessing function is a lambda function; return a boolean
9168-
is_lambda = re.match(r"^lambda", pre_text) is not None
9168+
# Determine if the preprocessing function is a lambda function; return a boolean
9169+
is_lambda = re.match(r"^lambda", pre_text) is not None
91699170

9170-
# If the preprocessing function is a lambda function, then check if there is
9171-
# a keyword argument called `dfn` in the lamda signature; if so, that's a cue
9172-
# to use a Narwhalified version of the table
9173-
if is_lambda:
9174-
# Get the signature of the lambda function
9175-
sig = inspect.signature(validation.pre)
9171+
# If the preprocessing function is a lambda function, then check if there is
9172+
# a keyword argument called `dfn` in the lamda signature; if so, that's a cue
9173+
# to use a Narwhalified version of the table
9174+
if is_lambda:
9175+
# Get the signature of the lambda function
9176+
sig = inspect.signature(validation.pre)
91769177

9177-
# Check if the lambda function has a keyword argument called `dfn`
9178-
if "dfn" in sig.parameters:
9179-
# Convert the table to a Narwhals DataFrame
9180-
data_tbl_step = nw.from_native(data_tbl_step)
9178+
# Check if the lambda function has a keyword argument called `dfn`
9179+
if "dfn" in sig.parameters:
9180+
# Convert the table to a Narwhals DataFrame
9181+
data_tbl_step = nw.from_native(data_tbl_step)
91819182

9182-
# Apply the preprocessing function to the table
9183-
data_tbl_step = validation.pre(dfn=data_tbl_step)
9183+
# Apply the preprocessing function to the table
9184+
data_tbl_step = validation.pre(dfn=data_tbl_step)
91849185

9185-
# Convert the table back to its original format
9186-
data_tbl_step = nw.to_native(data_tbl_step)
9186+
# Convert the table back to its original format
9187+
data_tbl_step = nw.to_native(data_tbl_step)
91879188

9188-
else:
9189-
# Apply the preprocessing function to the table
9189+
else:
9190+
# Apply the preprocessing function to the table
9191+
data_tbl_step = validation.pre(data_tbl_step)
9192+
9193+
# If the preprocessing function is a function, apply it to the table
9194+
elif isinstance(validation.pre, Callable):
91909195
data_tbl_step = validation.pre(data_tbl_step)
91919196

9192-
# If the preprocessing function is a function, apply it to the table
9193-
elif isinstance(validation.pre, Callable):
9194-
data_tbl_step = validation.pre(data_tbl_step)
9197+
except Exception:
9198+
# If preprocessing fails, mark the validation as having an eval_error
9199+
validation.eval_error = True
9200+
end_time = datetime.datetime.now(datetime.timezone.utc)
9201+
validation.proc_duration_s = (end_time - start_time).total_seconds()
9202+
validation.time_processed = end_time.isoformat(timespec="milliseconds")
9203+
validation.active = False
9204+
continue
91959205

91969206
# ------------------------------------------------
91979207
# Segmentation stage

0 commit comments

Comments
 (0)