Skip to content

Commit deb56d9

Browse files
committed
reorder
1 parent f38d79b commit deb56d9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

pyiceberg/io/pyarrow.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,14 +1776,7 @@ def _cast_if_needed(self, field: NestedField, values: pa.Array) -> pa.Array:
17761776
file_field = self._file_schema.find_field(field.field_id)
17771777

17781778
if field.field_type.is_primitive:
1779-
if field.field_type != file_field.field_type:
1780-
target_schema = schema_to_pyarrow(
1781-
promote(file_field.field_type, field.field_type), include_field_ids=self._include_field_ids
1782-
)
1783-
if self._use_large_types is False:
1784-
target_schema = _pyarrow_schema_ensure_small_types(target_schema)
1785-
return values.cast(target_schema)
1786-
elif (target_type := schema_to_pyarrow(field.field_type, include_field_ids=self._include_field_ids)) != values.type:
1779+
if (target_type := schema_to_pyarrow(field.field_type, include_field_ids=self._include_field_ids)) != values.type:
17871780
if field.field_type == TimestampType():
17881781
# Downcasting of nanoseconds to microseconds
17891782
if (
@@ -1802,13 +1795,22 @@ def _cast_if_needed(self, field: NestedField, values: pa.Array) -> pa.Array:
18021795
pa.types.is_timestamp(target_type)
18031796
and target_type.tz == "UTC"
18041797
and pa.types.is_timestamp(values.type)
1805-
and values.type.tz in UTC_ALIASES
1798+
and (values.type.tz in UTC_ALIASES or values.type.tz is None)
18061799
):
18071800
if target_type.unit == "us" and values.type.unit == "ns" and self._downcast_ns_timestamp_to_us:
18081801
return values.cast(target_type, safe=False)
18091802
elif target_type.unit == "us" and values.type.unit in {"s", "ms", "us"}:
18101803
return values.cast(target_type)
18111804
raise ValueError(f"Unsupported schema projection from {values.type} to {target_type}")
1805+
1806+
if field.field_type != file_field.field_type:
1807+
target_schema = schema_to_pyarrow(
1808+
promote(file_field.field_type, field.field_type), include_field_ids=self._include_field_ids
1809+
)
1810+
if self._use_large_types is False:
1811+
target_schema = _pyarrow_schema_ensure_small_types(target_schema)
1812+
return values.cast(target_schema)
1813+
18121814
return values
18131815

18141816
def _construct_field(self, field: NestedField, arrow_type: pa.DataType) -> pa.Field:

0 commit comments

Comments
 (0)