Skip to content

Commit

Permalink
test: add unit tests for normalize_list_columns function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovler-Young committed Nov 21, 2024
1 parent dd615d0 commit 005d585
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/test_pdhelper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import pytest
import pandas as pd
from ia_collection_analyzer.pdhelper import normalize_list_columns

@pytest.mark.parametrize(
"input_df,expected_df",
[
# Test mixed single/list values
(
pd.DataFrame({
'col1': ['a', ['b', 'c'], 'd'],
'col2': [1, [2, 3], 4]
}),
pd.DataFrame({
'col1': [['a'], ['b', 'c'], ['d']],
'col2': [[1], [2, 3], [4]]
})
),
# Test single values only (should remain unchanged)
(
pd.DataFrame({'col1': ['a', 'b', 'c']}),
pd.DataFrame({'col1': ['a', 'b', 'c']})
),
# Test lists only (should remain unchanged)
(
pd.DataFrame({'col1': [['a'], ['b', 'c'], ['d']]}),
pd.DataFrame({'col1': [['a'], ['b', 'c'], ['d']]})
),
# Test empty DataFrame with colums
(
pd.DataFrame(columns=['col1']),
pd.DataFrame(columns=['col1'])
),
# Test empty DataFrame without columns
(
pd.DataFrame(),
pd.DataFrame()
),
# Test with None/null values
(
pd.DataFrame({'col1': ['a', None, ['b']]}),
pd.DataFrame({'col1': [['a'], None, ['b']]})
),
# Test multiple data types
(
pd.DataFrame({
'str_col': ['a', ['b'], 'c'],
'int_col': [1, [2], 3],
'float_col': [1.0, [2.0], 3.0],
'pure_list': [['x'], ['y'], ['z']]
}),
pd.DataFrame({
'str_col': [['a'], ['b'], ['c']],
'int_col': [[1], [2], [3]],
'float_col': [[1.0], [2.0], [3.0]],
'pure_list': [['x'], ['y'], ['z']]
})
)
]
)
def test_normalize_list_columns(input_df, expected_df):
result = normalize_list_columns(input_df)
pd.testing.assert_frame_equal(result, expected_df)

0 comments on commit 005d585

Please sign in to comment.