Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Nov 4, 2023
1 parent 91828ba commit 3b6e1a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/_core/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def test_variable_type():
assert variable_type(s, boolean_type="categorical") == "categorical"
assert variable_type(s, boolean_type="boolean") == "boolean"

# This should arguably be datmetime, but we don't currently handle it correctly
# Test is mainly asserting that this doesn't fail on the boolean check.
s = pd.timedelta_range(1, periods=3, freq="D").to_series()
assert variable_type(s) == "categorical"

s_cat = s.astype("category")
assert variable_type(s_cat, boolean_type="categorical") == "categorical"
assert variable_type(s_cat, boolean_type="numeric") == "categorical"
Expand All @@ -61,6 +66,9 @@ def test_variable_type():
assert variable_type(s, boolean_type="boolean") == "boolean"
assert variable_type(s, boolean_type="boolean", strict_boolean=True) == "numeric"

s = pd.Series([1, 0, 0])
assert variable_type(s, boolean_type="boolean") == "boolean"

s = pd.Series([pd.Timestamp(1), pd.Timestamp(2)])
assert variable_type(s) == "datetime"
assert variable_type(s.astype(object)) == "datetime"
Expand Down
5 changes: 5 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,11 @@ def test_variable_type(self):
assert variable_type(s.to_numpy()) == "categorical"
assert variable_type(s.to_list()) == "categorical"

# This should arguably be datmetime, but we don't currently handle it correctly
# Test is mainly asserting that this doesn't fail on the boolean check.
s = pd.timedelta_range(1, periods=3, freq="D").to_series()
assert variable_type(s) == "categorical"

s = pd.Series([True, False, False])
assert variable_type(s) == "numeric"
assert variable_type(s, boolean_type="categorical") == "categorical"
Expand Down

0 comments on commit 3b6e1a7

Please sign in to comment.