Skip to content

Commit

Permalink
Add thresh warning. Closes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
chris1610 committed Nov 29, 2020
1 parent 0914074 commit f3d8e91
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# History

# 0.8.0 (dev)
# 0.8.0 (2020-11-29)
- Fix styling for missing
- Counts would break on completely null columns. Filter those out.
- Add a warning if thresh is < 1

# 0.7.0 (2020-8-21)
- Add counts function to show the number of total and unique values in a column
- Some doc cleanups and clarifications
Expand Down
4 changes: 4 additions & 0 deletions sidetable/sidetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pandas as pd
from pandas.api.types import is_numeric_dtype
from functools import reduce
import warnings


@pd.api.extensions.register_dataframe_accessor("stb")
Expand Down Expand Up @@ -75,6 +76,9 @@ class count percent cumulative_count cumulative_percent
if thresh > 100:
raise AttributeError('Thresh must be <= 100')

if thresh <= 1:
warnings.warn(f'thresh should be expressed as a percentage. Did you mean {int(thresh*100)}?')

# Determine aggregation (counts or summation) for each item in column

# TODO: NaNs need to be handled better. Wait for pandas 1.1
Expand Down
8 changes: 8 additions & 0 deletions tests/test_sidetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from sidetable import sidetable
import pandas as pd
import warnings


@pytest.fixture
Expand Down Expand Up @@ -80,6 +81,13 @@ def test_cutoff(titanic):
assert table.shape == (5, 6)


def test_thresh_warning(titanic):
""" Validate user warning runs if threshold < 1
"""
with pytest.warns(UserWarning):
table = titanic.stb.freq(['class', 'deck'], value='fare', thresh=.94)


def test_missing(titanic):
"""Validate the missing table works
"""
Expand Down

0 comments on commit f3d8e91

Please sign in to comment.