Skip to content

Commit

Permalink
Move deprecation warnings to single function.
Browse files Browse the repository at this point in the history
  • Loading branch information
tompollard committed Jun 8, 2024
1 parent ef9ac75 commit 07dbb2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 10 additions & 0 deletions tableone/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
warnings.simplefilter('always', DeprecationWarning)


def handle_deprecated_parameters(labels, isnull, pval_test_name, remarks):
"""
Raise warnings for deprecated parameters.
"""
deprecated_parameter(labels, "labels", "Use 'rename' instead")
deprecated_parameter(isnull, "isnull", "Use 'missing' instead")
deprecated_parameter(pval_test_name, "pval_test_name", "Use 'htest_name' instead")
deprecated_parameter(remarks, "remarks", "Use test names instead (e.g. diptest = True)")


def deprecated_parameter(parameter, parameter_name, message, version=None):
"""
Raise warning for a deprecated parameter.
Expand Down
7 changes: 2 additions & 5 deletions tableone/tableone.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pandas as pd
from tabulate import tabulate

from tableone.deprecations import deprecated_parameter
from tableone.deprecations import handle_deprecated_parameters
from tableone.preprocessors import ensure_list, detect_categorical, order_categorical, get_groups
from tableone.statistics import Statistics
from tableone.tables import Tables
Expand Down Expand Up @@ -221,10 +221,7 @@ def __init__(self, data: pd.DataFrame,
tukey_test: bool = False,
pval_threshold: Optional[float] = None) -> None:

deprecated_parameter(labels, "labels", "Use 'rename' instead")
deprecated_parameter(isnull, "isnull", "Use 'missing' instead")
deprecated_parameter(pval_test_name, "pval_test_name", "Use 'htest_name' instead")
deprecated_parameter(remarks, "remarks", "Use test names instead (e.g. diptest = True)")
handle_deprecated_parameters(labels, isnull, pval_test_name, remarks)

self._columns = columns if columns else data.columns.to_list() # type: ignore

Expand Down

0 comments on commit 07dbb2d

Please sign in to comment.