|
6 | 6 | import hypothesis.strategies as st
|
7 | 7 | import parsy
|
8 | 8 | import pytest
|
| 9 | +from pytest import param |
9 | 10 |
|
10 | 11 | import ibis.expr.datatypes as dt
|
11 | 12 | import ibis.tests.strategies as its
|
@@ -159,6 +160,34 @@ def test_struct_with_string_types():
|
159 | 160 | )
|
160 | 161 |
|
161 | 162 |
|
| 163 | +@pytest.mark.parametrize( |
| 164 | + ("type_string", "expected_dtype"), |
| 165 | + [ |
| 166 | + ("struct<a: int32,>", {"a": dt.int32}), |
| 167 | + ("struct<a: int32, b: string , >", {"a": dt.int32, "b": dt.string}), |
| 168 | + ], |
| 169 | + ids=["single_field", "multiple_fields"], |
| 170 | +) |
| 171 | +def test_struct_trailing_comma(type_string, expected_dtype): |
| 172 | + result = dt.dtype(type_string) |
| 173 | + assert result == dt.Struct(expected_dtype) |
| 174 | + |
| 175 | + |
| 176 | +@pytest.mark.parametrize( |
| 177 | + "invalid_type_string", |
| 178 | + [ |
| 179 | + param("struct<,>", id="missing_key"), |
| 180 | + param("struct<a,>", id="missing_colon"), |
| 181 | + param("struct<b: ,>", id="missing_value"), |
| 182 | + param("struct<c:in,>", id="invalid_type"), |
| 183 | + param("struct<a:int,b:int64,,>", id="double_comma"), |
| 184 | + ], |
| 185 | +) |
| 186 | +def test_struct_trailing_comma_invalid(invalid_type_string): |
| 187 | + with pytest.raises(parsy.ParseError): |
| 188 | + dt.dtype(invalid_type_string) |
| 189 | + |
| 190 | + |
162 | 191 | def test_array_with_string_value_types():
|
163 | 192 | assert dt.Array("int32") == dt.Array(dt.int32)
|
164 | 193 | assert dt.Array(dt.Array("array<map<string, double>>")) == (
|
@@ -293,3 +322,7 @@ def test_parse_null():
|
293 | 322 | @h.given(roundtrippable_dtypes)
|
294 | 323 | def test_parse_dtype_roundtrip(dtype):
|
295 | 324 | assert dt.dtype(str(dtype)) == dtype
|
| 325 | + |
| 326 | + |
| 327 | +def test_parse_empty_struct(): |
| 328 | + assert dt.dtype("struct<>") == dt.Struct({}) |
0 commit comments