@@ -1896,13 +1896,13 @@ def _cast_if_needed(self, field: NestedField, values: pa.Array) -> pa.Array:
18961896 if field .field_type .is_primitive :
18971897 if (target_type := schema_to_pyarrow (field .field_type , include_field_ids = self ._include_field_ids )) != values .type :
18981898 if field .field_type == TimestampType ():
1899- # Downcasting of nanoseconds to microseconds
19001899 if (
19011900 pa .types .is_timestamp (target_type )
19021901 and not target_type .tz
19031902 and pa .types .is_timestamp (values .type )
19041903 and (values .type .tz in UTC_ALIASES or values .type .tz is None )
19051904 ):
1905+ # Downcasting of nanoseconds to microseconds
19061906 if target_type .unit == "us" and values .type .unit == "ns" and self ._downcast_ns_timestamp_to_us :
19071907 return values .cast (target_type , safe = False )
19081908 elif target_type .unit == "us" and values .type .unit in {"s" , "ms" , "us" }:
@@ -1915,6 +1915,7 @@ def _cast_if_needed(self, field: NestedField, values: pa.Array) -> pa.Array:
19151915 and pa .types .is_timestamp (values .type )
19161916 and (values .type .tz in UTC_ALIASES or values .type .tz is None )
19171917 ):
1918+ # Downcasting of nanoseconds to microseconds
19181919 if target_type .unit == "us" and values .type .unit == "ns" and self ._downcast_ns_timestamp_to_us :
19191920 return values .cast (target_type , safe = False )
19201921 elif target_type .unit == "us" and values .type .unit in {"s" , "ms" , "us" }:
0 commit comments