From 7fe94db6494ae3ae92eeea1c86a3ba6464e0e858 Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Thu, 13 Jun 2024 00:25:24 -0400 Subject: [PATCH] Add exceptions module. --- tableone/exceptions.py | 6 ++++++ tableone/preprocessors.py | 2 +- tableone/statistics.py | 2 +- tableone/tables.py | 2 +- tableone/validators.py | 7 +------ 5 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 tableone/exceptions.py diff --git a/tableone/exceptions.py b/tableone/exceptions.py new file mode 100644 index 0000000..c6705f7 --- /dev/null +++ b/tableone/exceptions.py @@ -0,0 +1,6 @@ +"""Exceptions and warnings""" + + +class InputError(Exception): + """Custom exception for input validation errors.""" + pass \ No newline at end of file diff --git a/tableone/preprocessors.py b/tableone/preprocessors.py index 6e1259b..caf7646 100644 --- a/tableone/preprocessors.py +++ b/tableone/preprocessors.py @@ -1,6 +1,6 @@ import numpy as np -from tableone.validators import InputError +from tableone.exceptions import InputError def ensure_list(arg, arg_name): diff --git a/tableone/statistics.py b/tableone/statistics.py index 1719597..29389a2 100644 --- a/tableone/statistics.py +++ b/tableone/statistics.py @@ -7,7 +7,7 @@ from statsmodels.stats import multitest from tableone.modality import hartigan_diptest -from tableone.validators import InputError +from tableone.exceptions import InputError class Statistics: diff --git a/tableone/tables.py b/tableone/tables.py index fa34096..e35c743 100644 --- a/tableone/tables.py +++ b/tableone/tables.py @@ -5,7 +5,7 @@ import pandas as pd from tableone.statistics import Statistics -from tableone.validators import InputError +from tableone.exceptions import InputError class Tables: diff --git a/tableone/validators.py b/tableone/validators.py index b0d3240..4d93f27 100644 --- a/tableone/validators.py +++ b/tableone/validators.py @@ -3,11 +3,6 @@ import pandas as pd -class InputError(Exception): - """Custom exception for input validation errors.""" - pass - - class DataValidator: def __init__(self): """Initialize the DataValidator class.""" @@ -169,5 +164,5 @@ def check_columns_exist(self, columns: list, categorical: list, continuous: list all_specified = cat_set.union(cont_set) if not all_specified.issubset(set(columns)): missing = list(all_specified - set(columns)) - msg = "Specified categorical/continuous columns not found in the DataFrame: f"{missing}" + msg = f"Specified categorical/continuous columns not found in the DataFrame: {missing}" raise ValueError(msg)