-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add code and test for summary function
- Loading branch information
1 parent
3175308
commit 8b86d46
Showing
3 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import pytest | ||
import pandas as pd | ||
import os | ||
from pyeda.check_csv import check_csv | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pytest | ||
import pandas as pd | ||
from pyeda.data_summary import get_summary_statistics | ||
|
||
@pytest.fixture | ||
def sample_df(): | ||
data = { | ||
"numeric": [1, 2, 3, 4, 5], | ||
"categorical": ["a", "b", "a", "a", "c"], | ||
"missing": [None, None, None, None, None] | ||
} | ||
return pd.DataFrame(data) | ||
|
||
def test_for_all_columns(sample_df): | ||
"""Test the result of get summary function for all columns""" | ||
result = get_summary_statistics(sample_df) | ||
|
||
assert isinstance(result, pd.DataFrame) | ||
assert "mean" in result.index | ||
assert "std" in result.index | ||
assert "median" in result.index | ||
assert "unique_values" in result.index | ||
assert "most_frequent_value" in result.index | ||
assert result.loc["mean", "numeric"] == 3 | ||
assert result.loc["most_frequent_value", "categorical"] == "a" | ||
|
||
def test_for_selected_columns(sample_df): | ||
"""Test the result of get summary function for selected columns""" | ||
result = get_summary_statistics(sample_df, col=["numeric", "categorical"]) | ||
|
||
assert "numeric" in result.columns | ||
assert "categorical" in result.columns | ||
|
||
def test_for_empty_dataframe(): | ||
"""Test the result of empty dataframe""" | ||
df = pd.DataFrame() | ||
result = get_summary_statistics(df) | ||
assert result.empty | ||
|
||
def test_for_invalid_columns(sample_df): | ||
"""Test the result of invalid columns""" | ||
with pytest.raises(KeyError): | ||
get_summary_statistics(sample_df, col=["non_exist"]) |