2121import pyarrow as pa
2222import pytest
2323
24- from pyiceberg import schema
2524from pyiceberg .exceptions import ResolveError , ValidationError
2625from pyiceberg .schema import (
2726 Accessor ,
2827 Schema ,
2928 build_position_accessors ,
29+ index_by_id ,
30+ index_by_name ,
3031 promote ,
3132 prune_columns ,
3233 sanitize_column_names ,
@@ -90,15 +91,15 @@ def test_schema_str(table_schema_simple: Schema) -> None:
9091
9192def test_schema_repr_single_field () -> None :
9293 """Test schema representation"""
93- actual = repr (schema . Schema (NestedField (field_id = 1 , name = "foo" , field_type = StringType ()), schema_id = 1 ))
94+ actual = repr (Schema (NestedField (field_id = 1 , name = "foo" , field_type = StringType ()), schema_id = 1 ))
9495 expected = "Schema(NestedField(field_id=1, name='foo', field_type=StringType(), required=False), schema_id=1, identifier_field_ids=[])"
9596 assert expected == actual
9697
9798
9899def test_schema_repr_two_fields () -> None :
99100 """Test schema representation"""
100101 actual = repr (
101- schema . Schema (
102+ Schema (
102103 NestedField (field_id = 1 , name = "foo" , field_type = StringType ()),
103104 NestedField (field_id = 2 , name = "bar" , field_type = IntegerType (), required = False ),
104105 schema_id = 1 ,
@@ -111,7 +112,7 @@ def test_schema_repr_two_fields() -> None:
111112def test_schema_raise_on_duplicate_names () -> None :
112113 """Test schema representation"""
113114 with pytest .raises (ValueError ) as exc_info :
114- schema . Schema (
115+ Schema (
115116 NestedField (field_id = 1 , name = "foo" , field_type = StringType (), required = False ),
116117 NestedField (field_id = 2 , name = "bar" , field_type = IntegerType (), required = True ),
117118 NestedField (field_id = 3 , name = "baz" , field_type = BooleanType (), required = False ),
@@ -125,7 +126,7 @@ def test_schema_raise_on_duplicate_names() -> None:
125126
126127def test_schema_index_by_id_visitor (table_schema_nested : Schema ) -> None :
127128 """Test index_by_id visitor function"""
128- index = schema . index_by_id (table_schema_nested )
129+ index = index_by_id (table_schema_nested )
129130 assert index == {
130131 1 : NestedField (field_id = 1 , name = "foo" , field_type = StringType (), required = False ),
131132 2 : NestedField (field_id = 2 , name = "bar" , field_type = IntegerType (), required = True ),
@@ -198,7 +199,7 @@ def test_schema_index_by_id_visitor(table_schema_nested: Schema) -> None:
198199
199200def test_schema_index_by_name_visitor (table_schema_nested : Schema ) -> None :
200201 """Test index_by_name visitor function"""
201- table_schema_nested = schema . Schema (
202+ table_schema_nested = Schema (
202203 NestedField (field_id = 1 , name = "foo" , field_type = StringType (), required = False ),
203204 NestedField (field_id = 2 , name = "bar" , field_type = IntegerType (), required = True ),
204205 NestedField (field_id = 3 , name = "baz" , field_type = BooleanType (), required = False ),
@@ -245,7 +246,7 @@ def test_schema_index_by_name_visitor(table_schema_nested: Schema) -> None:
245246 schema_id = 1 ,
246247 identifier_field_ids = [2 ],
247248 )
248- index = schema . index_by_name (table_schema_nested )
249+ index = index_by_name (table_schema_nested )
249250 assert index == {
250251 "foo" : 1 ,
251252 "bar" : 2 ,
@@ -301,7 +302,7 @@ def test_schema_find_column_name_by_id(table_schema_simple: Schema) -> None:
301302
302303def test_schema_find_field_by_id (table_schema_simple : Schema ) -> None :
303304 """Test finding a column using its field ID"""
304- index = schema . index_by_id (table_schema_simple )
305+ index = index_by_id (table_schema_simple )
305306
306307 column1 = index [1 ]
307308 assert isinstance (column1 , NestedField )
@@ -324,15 +325,15 @@ def test_schema_find_field_by_id(table_schema_simple: Schema) -> None:
324325
325326def test_schema_find_field_by_id_raise_on_unknown_field (table_schema_simple : Schema ) -> None :
326327 """Test raising when the field ID is not found among columns"""
327- index = schema . index_by_id (table_schema_simple )
328+ index = index_by_id (table_schema_simple )
328329 with pytest .raises (Exception ) as exc_info :
329330 _ = index [4 ]
330331 assert str (exc_info .value ) == "4"
331332
332333
333334def test_schema_find_field_type_by_id (table_schema_simple : Schema ) -> None :
334335 """Test retrieving a columns' type using its field ID"""
335- index = schema . index_by_id (table_schema_simple )
336+ index = index_by_id (table_schema_simple )
336337 assert index [1 ] == NestedField (field_id = 1 , name = "foo" , field_type = StringType (), required = False )
337338 assert index [2 ] == NestedField (field_id = 2 , name = "bar" , field_type = IntegerType (), required = True )
338339 assert index [3 ] == NestedField (field_id = 3 , name = "baz" , field_type = BooleanType (), required = False )
@@ -341,7 +342,7 @@ def test_schema_find_field_type_by_id(table_schema_simple: Schema) -> None:
341342def test_index_by_id_schema_visitor_raise_on_unregistered_type () -> None :
342343 """Test raising a NotImplementedError when an invalid type is provided to the index_by_id function"""
343344 with pytest .raises (NotImplementedError ) as exc_info :
344- schema . index_by_id ("foo" ) # type: ignore
345+ index_by_id ("foo" ) # type: ignore
345346 assert "Cannot visit non-type: foo" in str (exc_info .value )
346347
347348
0 commit comments