|
31 | 31 | import pyarrow as pa |
32 | 32 | import shapely.geometry # type: ignore |
33 | 33 |
|
| 34 | +import bigframes.core.backports |
34 | 35 | import bigframes.exceptions |
35 | 36 |
|
36 | 37 | # Type hints for Pandas dtypes supported by BigQuery DataFrame |
@@ -372,8 +373,7 @@ def get_struct_fields(type_: ExpressionType) -> dict[str, Dtype]: |
372 | 373 | assert isinstance(type_.pyarrow_dtype, pa.StructType) |
373 | 374 | struct_type = type_.pyarrow_dtype |
374 | 375 | result: dict[str, Dtype] = {} |
375 | | - for field_no in range(struct_type.num_fields): |
376 | | - field = struct_type.field(field_no) |
| 376 | + for field in bigframes.core.backports.pyarrow_struct_type_fields(struct_type): |
377 | 377 | result[field.name] = arrow_dtype_to_bigframes_dtype(field.type) |
378 | 378 | return result |
379 | 379 |
|
@@ -551,7 +551,8 @@ def arrow_type_to_literal( |
551 | 551 | return [arrow_type_to_literal(arrow_type.value_type)] |
552 | 552 | if pa.types.is_struct(arrow_type): |
553 | 553 | return { |
554 | | - field.name: arrow_type_to_literal(field.type) for field in arrow_type.fields |
| 554 | + field.name: arrow_type_to_literal(field.type) |
| 555 | + for field in bigframes.core.backports.pyarrow_struct_type_fields(arrow_type) |
555 | 556 | } |
556 | 557 | if pa.types.is_string(arrow_type): |
557 | 558 | return "string" |
@@ -930,7 +931,8 @@ def contains_db_dtypes_json_arrow_type(type_): |
930 | 931 |
|
931 | 932 | if isinstance(type_, pa.StructType): |
932 | 933 | return any( |
933 | | - contains_db_dtypes_json_arrow_type(field.type) for field in type_.fields |
| 934 | + contains_db_dtypes_json_arrow_type(field.type) |
| 935 | + for field in bigframes.core.backports.pyarrow_struct_type_fields(type_) |
934 | 936 | ) |
935 | 937 | return False |
936 | 938 |
|
|
0 commit comments