@@ -13,16 +13,18 @@ def cast_pyarrow_table_schema(data: pa.Table, schema: pa.Schema) -> pa.Table:
1313 Returns:
1414 pa.Table: A new pyarrow table with correct schema.
1515 """
16+ # Pyarrow has only partial type hints. All type: ignore in this function has been
17+ # checked with the pyarrow documentation, and the implementation is correct.
1618 newdata = []
1719 newnames = []
1820 for field in schema :
19- if type (field .type ) is pa .DictionaryType :
20- new = data .column (field .name ).dictionary_encode ().cast (field .type )
21+ if type (field .type ) is pa .DictionaryType : # type: ignore
22+ new = data .column (field .name ).dictionary_encode ().cast (field .type ) # type: ignore
2123 else :
22- new = data .column (field .name ).cast (field .type )
24+ new = data .column (field .name ).cast (field .type ) # type: ignore
2325 newdata .append (new )
2426 newnames .append (field .name )
25- return pa .table (newdata , names = newnames )
27+ return pa .table (newdata , names = newnames ) # type: ignore
2628
2729
2830def restructur_pyarrow_schema (
@@ -46,17 +48,19 @@ def restructur_pyarrow_schema(
4648 pa.Schema: A new pyarrow schema that has the same order as the in use schema,
4749 but with the correct datatypes from the schema that we want.
4850 """
51+ # Pyarrow has only partial type hints. All type: ignore in this function has been
52+ # checked with the pyarrow documentation, and the implementation is correct.
4953 for col in inuse_schema .names :
5054 assert col in wanted_schema .names
5155 newfields = []
5256 for name in inuse_schema .names :
5357 inuse_field_index = inuse_schema .get_field_index (name )
5458 wanted_field_index = wanted_schema .get_field_index (name )
55- inuse_field = inuse_schema .field (inuse_field_index )
56- wanted_field = wanted_schema .field (wanted_field_index )
59+ inuse_field = inuse_schema .field (inuse_field_index ) # type: ignore
60+ wanted_field = wanted_schema .field (wanted_field_index ) # type:ignore
5761
58- if type (inuse_field .type ) is type (wanted_field .type ):
59- newfields .append (inuse_field .with_type (wanted_field .type ))
62+ if type (inuse_field .type ) is type (wanted_field .type ): # type: ignore
63+ newfields .append (inuse_field .with_type (wanted_field .type )) # type: ignore
6064 else :
6165 newfields .append (wanted_field )
6266 return pa .schema (newfields )
0 commit comments