Skip to content

Commit

Permalink
Add test for include_null for categorical data type.
Browse files Browse the repository at this point in the history
  • Loading branch information
tompollard committed Jun 16, 2024
1 parent 51b9c56 commit b4288fc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/unit/test_tableone.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,3 +1242,21 @@ def test_mutual_exclusivity_of_continuous_and_categorical(self, data_sample):

# Ensure that the error message matches the one produced by the code
assert "Columns cannot be both categorical and continuous" in str(excinfo.value)

def test_null_values_correctly_handled_for_categorical_data_type(self):
"""
Checks that null values are converted to a new category for categorical column type.
Issue raised by @eroell in https://github.com/tompollard/tableone/issues/177.
"""
dummy_table = pd.DataFrame(
{
"age": [70, 80, 90, 85, 70],
"sex": ["m", "f", "m", "f", None]
}
)
dummy_table["sex"] = dummy_table["sex"].astype("category")
t = TableOne(dummy_table, include_null=True)

expected = '1 (20.0)'
assert t.tableone.loc["sex, n (%)", "None"]["Overall"] == expected

0 comments on commit b4288fc

Please sign in to comment.