|
31 | 31 | PySparkAnalysisException,
|
32 | 32 | TrinoUserError,
|
33 | 33 | )
|
| 34 | +from ibis.common.annotations import ValidationError |
34 | 35 | from ibis.common.collections import frozendict
|
35 | 36 |
|
36 | 37 | pytestmark = [
|
|
72 | 73 | # list.
|
73 | 74 |
|
74 | 75 |
|
| 76 | +def test_array_factory(con): |
| 77 | + a = ibis.array([1, 2, 3]) |
| 78 | + assert a.type() == dt.Array(value_type=dt.Int8) |
| 79 | + assert con.execute(a) == [1, 2, 3] |
| 80 | + |
| 81 | + a2 = ibis.array(a) |
| 82 | + assert a.type() == dt.Array(value_type=dt.Int8) |
| 83 | + assert con.execute(a2) == [1, 2, 3] |
| 84 | + |
| 85 | + |
| 86 | +@pytest.mark.broken( |
| 87 | + ["pandas", "dask"], |
| 88 | + raises=AssertionError, |
| 89 | + reason="results in [1, 2, 3]", |
| 90 | +) |
| 91 | +def test_array_factory_typed(con): |
| 92 | + typed = ibis.array([1, 2, 3], type="array<string>") |
| 93 | + assert con.execute(typed) == ["1", "2", "3"] |
| 94 | + |
| 95 | + typed2 = ibis.array(ibis.array([1, 2, 3]), type="array<string>") |
| 96 | + assert con.execute(typed2) == ["1", "2", "3"] |
| 97 | + |
| 98 | + |
| 99 | +@pytest.mark.notimpl("flink", raises=Py4JJavaError) |
| 100 | +@pytest.mark.notimpl(["pandas", "dask"], raises=ValueError) |
| 101 | +def test_array_factory_empty(con): |
| 102 | + with pytest.raises(ValidationError): |
| 103 | + ibis.array([]) |
| 104 | + |
| 105 | + empty_typed = ibis.array([], type="array<string>") |
| 106 | + assert empty_typed.type() == dt.Array(value_type=dt.string) |
| 107 | + assert con.execute(empty_typed) == [] |
| 108 | + |
| 109 | + |
| 110 | +@pytest.mark.notyet( |
| 111 | + "clickhouse", raises=ClickHouseDatabaseError, reason="nested types can't be NULL" |
| 112 | +) |
| 113 | +@pytest.mark.notyet( |
| 114 | + "flink", raises=Py4JJavaError, reason="Parameters must be of the same type" |
| 115 | +) |
| 116 | +def test_array_factory_null(con): |
| 117 | + with pytest.raises(ValidationError): |
| 118 | + ibis.array(None) |
| 119 | + with pytest.raises(ValidationError): |
| 120 | + ibis.array(None, type="int64") |
| 121 | + none_typed = ibis.array(None, type="array<string>") |
| 122 | + assert none_typed.type() == dt.Array(value_type=dt.string) |
| 123 | + assert con.execute(none_typed) is None |
| 124 | + |
| 125 | + nones = ibis.array([None, None], type="array<string>") |
| 126 | + assert nones.type() == dt.Array(value_type=dt.string) |
| 127 | + assert con.execute(nones) == [None, None] |
| 128 | + |
| 129 | + # Execute a real value here, so the backends that don't support arrays |
| 130 | + # actually xfail as we expect them to. |
| 131 | + # Otherwise would have to @mark.xfail every test in this file besides this one. |
| 132 | + assert con.execute(ibis.array([1, 2])) == [1, 2] |
| 133 | + |
| 134 | + |
| 135 | +@pytest.mark.broken( |
| 136 | + ["datafusion", "flink", "polars"], |
| 137 | + raises=AssertionError, |
| 138 | + reason="[None, 1] executes to [np.nan, 1.0]", |
| 139 | +) |
| 140 | +@pytest.mark.broken( |
| 141 | + ["pandas", "dask"], |
| 142 | + raises=AssertionError, |
| 143 | + reason="even with explicit cast, results in [None, 1]", |
| 144 | +) |
| 145 | +def test_array_factory_null_mixed(con): |
| 146 | + none_and_val = ibis.array([None, 1]) |
| 147 | + assert none_and_val.type() == dt.Array(value_type=dt.Int8) |
| 148 | + assert con.execute(none_and_val) == [None, 1] |
| 149 | + |
| 150 | + none_and_val_typed = ibis.array([None, 1], type="array<string>") |
| 151 | + assert none_and_val_typed.type() == dt.Array(value_type=dt.String) |
| 152 | + assert con.execute(none_and_val_typed) == [None, "1"] |
| 153 | + |
| 154 | + |
75 | 155 | def test_array_column(backend, alltypes, df):
|
76 | 156 | expr = ibis.array(
|
77 | 157 | [alltypes["double_col"], alltypes["double_col"], 5.0, ibis.literal(6.0)]
|
@@ -1354,11 +1434,6 @@ def test_unnest_range(con):
|
1354 | 1434 | id="array",
|
1355 | 1435 | marks=[
|
1356 | 1436 | pytest.mark.notyet(["bigquery"], raises=GoogleBadRequest),
|
1357 |
| - pytest.mark.broken( |
1358 |
| - ["polars"], |
1359 |
| - reason="expression input not supported with nested arrays", |
1360 |
| - raises=TypeError, |
1361 |
| - ), |
1362 | 1437 | ],
|
1363 | 1438 | ),
|
1364 | 1439 | ],
|
|
0 commit comments