Skip to content

Commit

Permalink
Fixed check.continuous to accept int32, float32 and uint32 (#159)
Browse files Browse the repository at this point in the history
* fixed check.continuous to accept int32, float32 and uint32

* fix sonar issues
  • Loading branch information
marqueewinq authored Jan 22, 2024
1 parent 5f19bc5 commit 91c70df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/insight/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ def continuous(self, sr: pd.Series) -> bool:
All arithmetic operations can be done on continuous columns
"""
sr = self.infer_dtype(sr)
sr_dtype = str(sr.dtype)
if len(sr.unique()) >= max(
self.min_num_unique, self.ctl_mult * np.log(len(sr))
) and sr_dtype in ("float64", "int64"):
) and sr.dtype.kind in ("i", "u", "f"):
return True
return False

Expand Down
22 changes: 22 additions & 0 deletions tests/test_metrics/test_plotting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import string
from unittest.mock import patch

import numpy as np
import pandas as pd
import pytest

Expand Down Expand Up @@ -97,3 +101,21 @@ def test_plot_dataset_two_datasets_not_equal_not_none(df_half_a, df_half_b):
assert fig_b is not None

assert fig_a != fig_b


def test_plot_dataset_int32_float32():
def create_df(n_size=100, n_int32_max=100, n_int64_max=100, n_uint32_max=100):
df = pd.DataFrame()
df["float32"] = np.random.random(size=n_size).astype(np.float32)
df["float64"] = np.random.random(size=n_size).astype(np.float64)
df["int32"] = np.random.randint(n_int32_max, size=n_size).astype(np.int32)
df["int64"] = np.random.randint(n_int64_max, size=n_size).astype(np.int64)
df["uint32"] = np.random.randint(n_uint32_max, size=n_size).astype(np.uint32)
df["object"] = np.random.choice(list("abcde"), size=n_size)
return df

n_size = 100
with patch("insight.plot.text_only") as mock_text_only:
dataset([create_df(n_size), create_df(n_size)]) # assert not failed

mock_text_only.assert_not_called()

0 comments on commit 91c70df

Please sign in to comment.