Skip to content

Commit

Permalink
Move warning to exceptions module.
Browse files Browse the repository at this point in the history
  • Loading branch information
tompollard committed Jun 16, 2024
1 parent 9208822 commit 6e7f4bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 7 additions & 1 deletion tableone/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""Exceptions and warnings"""
import warnings


class InputError(Exception):
"""Custom exception for input validation errors."""
pass
pass

def non_continuous_warning(c):
msg = ("'{}' has all non-numeric values. Consider including "
"it in the list of categorical variables.").format(c)
warnings.warn(msg, RuntimeWarning, stacklevel=2)
11 changes: 2 additions & 9 deletions tableone/tables.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Optional
import warnings

import numpy as np
import pandas as pd

from tableone.statistics import Statistics
from tableone.exceptions import InputError
from tableone.exceptions import InputError, non_continuous_warning


class Tables:
Expand Down Expand Up @@ -363,7 +362,7 @@ def std(x):

# check for coerced column containing all NaN to warn user
for column in cont_data.columns[cont_data.count() == 0]:
self._non_continuous_warning(column)
non_continuous_warning(column)

if groupby:
# add the groupby column back
Expand All @@ -386,12 +385,6 @@ def std(x):

return df_cont

# warnings
def _non_continuous_warning(self, c):
msg = ("'{}' has all non-numeric values. Consider including "
"it in the list of categorical variables.").format(c)
warnings.warn(msg, RuntimeWarning, stacklevel=2)

def create_cont_table(self,
data,
overall,
Expand Down

0 comments on commit 6e7f4bc

Please sign in to comment.