Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

making column checking robust to passing pandas index #61

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions tableone.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def __init__(self, data, columns=None, categorical=None, groupby=None,
nonnormal = [nonnormal]

# if columns not specified, use all columns
if not columns:
if type(columns) == type(None):
columns = data.columns.get_values()
elif 'pandas.core.indexes' in str(type(columns)):
columns = columns.get_values()

# check that the columns exist in the dataframe
if not set(columns).issubset(data.columns):
Expand All @@ -98,7 +100,11 @@ def __init__(self, data, columns=None, categorical=None, groupby=None,
raise InputError('Input contains duplicate columns: {}'.format(dups))

# if categorical not specified, try to identify categorical
if not categorical and type(categorical) != list:
if type(columns) == type(None):
categorical = self._detect_categorical_columns(data[columns])
elif 'pandas.core.indexes' in str(type(categorical)):
categorical = categorical.get_values()
elif type(categorical) != list:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone specifies a single categorical variable as a string (e.g. categorical = 'ICU'), then I think we now ignore their selection and generate the list ourselves. Might be good to catch the string too?

categorical = self._detect_categorical_columns(data[columns])

if pval and not groupby:
Expand Down Expand Up @@ -267,7 +273,7 @@ def _normaltest(self,x):
Compute test for normal distribution.

Null hypothesis: x comes from a normal distribution
p < alpha suggests the null hypothesis can be rejected.
p < alpha suggests the null hypothesis can be rejected.
"""
stat,p = stats.normaltest(x.values, nan_policy='omit')
return p
Expand Down