|
14 | 14 | from datetime import datetime
|
15 | 15 | from unittest import TestCase
|
16 | 16 |
|
| 17 | +import pytest |
17 | 18 | from bson import Binary, Code, Decimal128, Int64, ObjectId
|
18 | 19 | from pyarrow import Table, field, float64, int64, list_, struct, timestamp
|
19 | 20 | from pyarrow import schema as ArrowSchema
|
@@ -94,3 +95,22 @@ def test_list_of_list_projection(self):
|
94 | 95 | }
|
95 | 96 | )
|
96 | 97 | self.assertEqual(schema._get_projection(), {"_id": True, "list": {"a": True, "b": True}})
|
| 98 | + |
| 99 | + def test_py_list_projection(self): |
| 100 | + schema = Schema( |
| 101 | + {"_id": ObjectId, "list": [(struct([field("a", int64()), field("b", float64())]))]} |
| 102 | + ) |
| 103 | + |
| 104 | + self.assertEqual(schema._get_projection(), {"_id": True, "list": {"a": True, "b": True}}) |
| 105 | + |
| 106 | + def test_py_list_with_multiple_fields_raises(self): |
| 107 | + with pytest.raises( |
| 108 | + ValueError, match="list field in schema must contain exactly one element, not 2" |
| 109 | + ): |
| 110 | + _ = Schema({"_id": ObjectId, "list": [([field("a", int64()), field("b", float64())])]}) |
| 111 | + |
| 112 | + def test_py_empty_list_raises(self): |
| 113 | + with pytest.raises( |
| 114 | + ValueError, match="list field in schema must contain exactly one element, not 0" |
| 115 | + ): |
| 116 | + _ = Schema({"_id": ObjectId, "list": []}) |
0 commit comments