Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edknv committed Jan 19, 2024
1 parent e925b25 commit 6f03f59
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/backend/cudf_backend/test_series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest

cudf = pytest.importorskip("cudf")
torch = pytest.importorskip("torch")

from crossfit.backend.cudf.series import ( # noqa: E402
create_list_series_from_1d_or_2d_ar,
create_nested_list_series_from_3d_ar,
)


@pytest.mark.singlegpu
def test_create_list_series_from_1d_or_2d_ar_1d():
tensor = torch.tensor([101, 102, 103])
index = [1, 2, 3]
series = create_list_series_from_1d_or_2d_ar(tensor, index)
assert isinstance(series, cudf.Series)
expected = cudf.Series([[101], [102], [103]], index=index)
# convert to pandas because cudf.Series.equals doesn't work for list series
assert series.to_pandas().equals(expected.to_pandas())


@pytest.mark.singlegpu
def test_create_list_series_from_1d_or_2d_ar_2d():
tensor = torch.tensor([[101, 102], [103, 104], [105, 106]])
index = [1, 2, 3]
series = create_list_series_from_1d_or_2d_ar(tensor, index)
assert isinstance(series, cudf.Series)
expected = cudf.Series([[101, 102], [103, 104], [105, 106]], index=index)
# convert to pandas because cudf.Series.equals doesn't work for list series
assert series.to_pandas().equals(expected.to_pandas())


@pytest.mark.singlegpu
def test_create_nested_list_series_from_3d_ar():
nested_list = [[[101, 102], [103, 104], [105, 106]], [[201, 202], [203, 204], [205, 206]]]
tensor = torch.tensor(nested_list)
index = [1, 2]
series = create_nested_list_series_from_3d_ar(tensor, index)
print(series)
assert isinstance(series, cudf.Series)
expected = cudf.Series(nested_list, index=index)
# convert to pandas because cudf.Series.equals doesn't work for list series
assert series.to_pandas().equals(expected.to_pandas())

0 comments on commit 6f03f59

Please sign in to comment.