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 all commits
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
16 changes: 12 additions & 4 deletions tableone.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ 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()
else:
columns = list(columns)

# check that the columns exist in the dataframe
if not set(columns).issubset(data.columns):
Expand All @@ -98,13 +102,17 @@ 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()
else:
categorical = list(columns)

if pval and not groupby:
raise InputError("If pval=True then the groupby must be specified.")

self._columns = list(columns)
self._columns = columns
self._isnull = isnull
self._continuous = [c for c in columns if c not in categorical + [groupby]]
self._categorical = categorical
Expand Down Expand Up @@ -267,7 +275,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