Skip to content

Commit

Permalink
fix(test):Updated the test_missing.py with edge case 'None'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhengHe-007 committed Feb 3, 2025
1 parent 34f79ff commit a039574
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ def df_no_missing():
}
return pd.DataFrame(data)

@pytest.fixture
def df_with_none():
"""
Fixture to create a DataFrame that contains None values.
"""
data = {
'A': [1, None, pd.NA, 4], # None and pd.NA mixed in column A
'B': [None, None, 3, 4], # Only None values in column B
'C': [1, 2, 3, 4] # No missing values in column C
}
return pd.DataFrame(data)


def test_missing_values_summary(df):
"""
Expand All @@ -46,6 +58,7 @@ def test_missing_values_summary(df):
# Check the specific values in the Series
assert list(result.values) == expected_values, "Values in the Series do not match the expected output."


def test_no_missing_values(df_no_missing):
"""
Test case where no missing values exist in the DataFrame.
Expand All @@ -56,3 +69,23 @@ def test_no_missing_values(df_no_missing):
assert result.empty or result == "No missing value!", (
"Function should return 'No missing value!' or an empty Series when no missing values are present."
)


def test_missing_values_summary_with_none(df_with_none):
"""
Test case where the DataFrame contains None values.
"""
result = missing_values_summary(df_with_none)

# Expected results
expected_index = {'B', 'A'} # Use a set instead of a list (order-independent)
expected_values = ['2 (50.0%)', '2 (50.0%)'] # None values counted as missing

# Check if the result is a Series
assert isinstance(result, pd.Series), "Result should be a Series."

# Check if the resulting Series has the correct index (ignoring order)
assert set(result.index) == expected_index, "Index does not match the expected order."

# Check the specific values in the Series
assert list(result.values) == expected_values, "Values in the Series do not match the expected output."

0 comments on commit a039574

Please sign in to comment.