@@ -1839,13 +1839,13 @@ def _cast_if_needed(self, field: NestedField, values: pa.Array) -> pa.Array:
18391839 if field .field_type .is_primitive :
18401840 if (target_type := schema_to_pyarrow (field .field_type , include_field_ids = self ._include_field_ids )) != values .type :
18411841 if field .field_type == TimestampType ():
1842- # Downcasting of nanoseconds to microseconds
18431842 if (
18441843 pa .types .is_timestamp (target_type )
18451844 and not target_type .tz
18461845 and pa .types .is_timestamp (values .type )
18471846 and (values .type .tz in UTC_ALIASES or values .type .tz is None )
18481847 ):
1848+ # Downcasting of nanoseconds to microseconds
18491849 if target_type .unit == "us" and values .type .unit == "ns" and self ._downcast_ns_timestamp_to_us :
18501850 return values .cast (target_type , safe = False )
18511851 elif target_type .unit == "us" and values .type .unit in {"s" , "ms" , "us" }:
@@ -1858,6 +1858,7 @@ def _cast_if_needed(self, field: NestedField, values: pa.Array) -> pa.Array:
18581858 and pa .types .is_timestamp (values .type )
18591859 and (values .type .tz in UTC_ALIASES or values .type .tz is None )
18601860 ):
1861+ # Downcasting of nanoseconds to microseconds
18611862 if target_type .unit == "us" and values .type .unit == "ns" and self ._downcast_ns_timestamp_to_us :
18621863 return values .cast (target_type , safe = False )
18631864 elif target_type .unit == "us" and values .type .unit in {"s" , "ms" , "us" }:
0 commit comments