Skip to content

Commit

Permalink
tidying __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
tompollard committed Jun 8, 2024
1 parent 07dbb2d commit 265307c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
33 changes: 17 additions & 16 deletions tableone/tableone.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,8 @@ def __init__(self, data: pd.DataFrame,

handle_deprecated_parameters(labels, isnull, pval_test_name, remarks)

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

self.data_validator = DataValidator()
self.data_validator.validate(data, self._columns) # type: ignore

self.input_validator = InputValidator()
self.input_validator.validate(groupby, nonnormal, min_max, pval_adjust, order, # type: ignore
pval, self._columns, categorical, continuous) # type: ignore

self._alt_labels = rename
# if categorical is set to None, try to automatically detect
# if empty list is provided, assume there are no categorical variables.
self._columns = columns if columns else data.columns.to_list() # type: ignore
self._categorical = detect_categorical(data[self._columns], groupby) if categorical is None else categorical
if continuous:
self._continuous = continuous
Expand All @@ -261,13 +251,12 @@ def __init__(self, data: pd.DataFrame,
self._row_percent = row_percent
self._smd = smd
self._sort = sort
self.statistics = Statistics() # TODO: remove this after migrating to tables.py
self._tukey_test = tukey_test
self._warnings = {} # display notes and warnings below the table

self._warnings = {}
self._groupbylvls = get_groups(data, self._groupby, self._order, self._reserved_columns)

# Intermediate tables
self.statistics = Statistics()
self.tables = Tables()
self._htest_table = None
self.cat_describe_all = None
Expand All @@ -278,6 +267,10 @@ def __init__(self, data: pd.DataFrame,
self.cat_table = None
self.cont_table = None

# Set up validators and validate data
self.setup_validators()
self.validate_data(data)

# forgive me jraffa
if self._pval:
self._htest_table = self.tables.create_htest_table(data, self._continuous, self._categorical,
Expand Down Expand Up @@ -346,8 +339,6 @@ def __init__(self, data: pd.DataFrame,
self._groupby,
self.cat_describe_all)



if self._continuous:
self.cont_table = self.tables.create_cont_table(data,
self._overall,
Expand Down Expand Up @@ -386,6 +377,16 @@ def __repr__(self) -> str:
def _repr_html_(self) -> str:
return self.tableone._repr_html_() + self._generate_remarks('<br />')

def setup_validators(self):
self.data_validator = DataValidator()
self.input_validator = InputValidator()

def validate_data(self, data):
self.data_validator.validate(data, self._columns) # type: ignore
self.input_validator.validate(self._groupby, self._nonnormal, self._min_max, # type: ignore
self._pval_adjust, self._order, self._pval, # type: ignore
self._columns, self._categorical, self._continuous) # type: ignore

def _set_display_options(self):
"""
Set pandas display options. Display all rows and columns by default.
Expand Down
2 changes: 1 addition & 1 deletion tableone/validators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Optional, Union, Dict, Set
from typing import Any, List, Optional, Union, Dict

import pandas as pd

Expand Down

0 comments on commit 265307c

Please sign in to comment.