Skip to content

Commit

Permalink
Added tests to ensure correct errors being raised when accessing non-…
Browse files Browse the repository at this point in the history
…existent struct fields
  • Loading branch information
sft-managed authored and sft-managed committed Jul 29, 2021
1 parent 26bda21 commit dca6999
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python/cudf/cudf/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,25 @@ def test_struct_slice(series, start, end):
else:
expected = cudf.Series(series[start:end])
assert sr[start:end].to_arrow() == expected.to_arrow()


@pytest.mark.parametrize(
"data",
[
[{}],
[{"a": None}],
[{"a": 1}],
[{"a": "one"}],
[{"a": 1}, {"a": 2}],
[{"a": 1, "b": "one"}, {"a": 2, "b": "two"}],
[{"b": "two", "a": None}, None, {"a": "one", "b": "two"}],
],
)
def test_struct_field_errors(data):
got = cudf.Series(data)

with pytest.raises(KeyError):
got.struct.field("notWithinFields")

with pytest.raises(IndexError):
got.struct.field(100)

0 comments on commit dca6999

Please sign in to comment.