HyukjinKwon commented on a change in pull request #34631: URL: https://github.com/apache/spark/pull/34631#discussion_r751947212
########## File path: python/pyspark/sql/pandas/conversion.py ########## @@ -225,7 +227,10 @@ def toPandas(self) -> "PandasDataFrameLike": else: series = pdf[column_name] - if t is not None: + # No need to cast for empty series for timedelta. + should_check_timedelta = is_timedelta64_dtype(t) and len(pdf) == 0 Review comment: This is, BTW, to work around a bug from Arrow <> pandas. For some reasons, `pd.Series(pd.Timedelta(...), dtype="object")` created from Arrow becomes `float64` when you cast with `series.astype("timedelta64[us]")` when the data is non-empty - this cannot be reproduced with plain pandas `Series`. So, here I avoided it by just skipping the casting because the type becomes correct when it is not empty. When data is empty, the type becomes `object`, and it has to be casted. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org