Skip to content

Commit

Permalink
Minor formatting changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tompollard committed Jun 13, 2024
1 parent 9d98321 commit 8cc5795
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tableone/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ def check_groupby(self, groupby: str, pval: bool) -> None:
"""Ensure 'groupby' is provided as a str."""
if groupby:
if isinstance(groupby, list):
raise ValueError(f"Invalid 'groupby' type: expected a string, received a list. Use '{groupby[0]}' if it's the intended group.")
msg = (f"Invalid 'groupby' type: expected a string, received a list. "
f"Use '{groupby[0]}' if it's the intended group.")
raise ValueError(msg)
elif not isinstance(groupby, str):
raise TypeError(f"Invalid 'groupby' type: expected a string, received {type(groupby).__name__}.")
msg = f"Invalid 'groupby' type: expected a string, received {type(groupby).__name__}."
raise TypeError(msg)
elif pval:
raise ValueError("The 'pval' parameter is set to True, but no 'groupby' parameter was specified.")
msg = "The 'pval' parameter is set to True, but no 'groupby' parameter was specified."
raise ValueError(msg)

def check_list(self,
parameter: Optional[Union[List[Any], str]],
Expand All @@ -104,7 +108,9 @@ def check_list(self,
"""Ensure list arguments are properly formatted."""
if parameter:
if not isinstance(parameter, (list, str)):
raise TypeError(f"Invalid '{parameter_name}' type: expected a list or a string, received {type(parameter).__name__}.")
msg = (f"Invalid '{parameter_name}' type: expected a list "
f"or a string, received {type(parameter).__name__}.")
raise TypeError(msg)
if expected_type and any(not isinstance(item, expected_type) for item in parameter):
raise ValueError(f"All items in '{parameter_name}' list must be of type {expected_type.__name__}.")

Expand All @@ -124,7 +130,9 @@ def check_order(self, order: dict):
"""Ensure the order argument is correctly specified."""
if order is not None:
if not isinstance(order, dict):
raise TypeError("The 'order' parameter must be a dictionary where keys are column names and values are lists of ordered categories.")
msg = ("The 'order' parameter must be a dictionary where keys are "
"column names and values are lists of ordered categories.")
raise TypeError(msg)

for key, values in order.items():
if not isinstance(values, list):
Expand Down Expand Up @@ -157,4 +165,4 @@ def check_columns_exist(self, columns: list, categorical: list, continuous: list
if not all_specified.issubset(set(columns)):
missing = list(all_specified - set(columns))
raise ValueError("Specified categorical/continuous columns not found in the DataFrame: "
f"{missing}")
f"{missing}")

0 comments on commit 8cc5795

Please sign in to comment.