|
17 | 17 | import pytest |
18 | 18 |
|
19 | 19 | import bigframes.bigquery as bbq |
| 20 | +import bigframes.dtypes |
20 | 21 | import bigframes.pandas as bpd |
21 | 22 |
|
22 | 23 |
|
23 | | -def test_array_length(): |
24 | | - series = bpd.Series([["A", "AA", "AAA"], ["BB", "B"], np.nan, [], ["C"]]) |
25 | | - # TODO(b/336880368): Allow for NULL values to be input for ARRAY columns. |
26 | | - # Once we actually store NULL values, this will be NULL where the input is NULL. |
27 | | - expected = bpd.Series([3, 2, 0, 0, 1]) |
| 24 | +@pytest.mark.parametrize( |
| 25 | + ["input_data", "expected"], |
| 26 | + [ |
| 27 | + pytest.param( |
| 28 | + [["A", "AA", "AAA"], ["BB", "B"], np.nan, [], ["C"]], |
| 29 | + [ |
| 30 | + 3, |
| 31 | + 2, |
| 32 | + # TODO(b/336880368): Allow for NULL values to be input for ARRAY |
| 33 | + # columns. Once we actually store NULL values, this will be |
| 34 | + # NULL where the input is NULL. |
| 35 | + 0, |
| 36 | + 0, |
| 37 | + 1, |
| 38 | + ], |
| 39 | + id="small-string", |
| 40 | + ), |
| 41 | + pytest.param( |
| 42 | + [[1, 2, 3], [4, 5], [], [], [6]], [3, 2, 0, 0, 1], id="small-int64" |
| 43 | + ), |
| 44 | + pytest.param( |
| 45 | + [ |
| 46 | + # Regression test for b/414374215 where the Series constructor |
| 47 | + # returns empty lists when the lists are too big to embed in |
| 48 | + # SQL. |
| 49 | + list(np.random.randint(-1_000_000, 1_000_000, size=1000)), |
| 50 | + list(np.random.randint(-1_000_000, 1_000_000, size=967)), |
| 51 | + list(np.random.randint(-1_000_000, 1_000_000, size=423)), |
| 52 | + list(np.random.randint(-1_000_000, 1_000_000, size=5000)), |
| 53 | + list(np.random.randint(-1_000_000, 1_000_000, size=1003)), |
| 54 | + list(np.random.randint(-1_000_000, 1_000_000, size=9999)), |
| 55 | + ], |
| 56 | + [ |
| 57 | + 1000, |
| 58 | + 967, |
| 59 | + 423, |
| 60 | + 5000, |
| 61 | + 1003, |
| 62 | + 9999, |
| 63 | + ], |
| 64 | + id="larger-int64", |
| 65 | + ), |
| 66 | + ], |
| 67 | +) |
| 68 | +def test_array_length(input_data, expected): |
| 69 | + series = bpd.Series(input_data) |
| 70 | + expected = pd.Series(expected, dtype=bigframes.dtypes.INT_DTYPE) |
28 | 71 | pd.testing.assert_series_equal( |
29 | 72 | bbq.array_length(series).to_pandas(), |
30 | | - expected.to_pandas(), |
| 73 | + expected, |
| 74 | + check_index_type=False, |
31 | 75 | ) |
32 | 76 |
|
33 | 77 |
|
|
0 commit comments