You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2023/01/10 12:03:53 UTC

[GitHub] [spark] zhengruifeng commented on a diff in pull request #39469: [SPARK-XXXX][CONNECT][PYTHON] Truncating nanoseconds timestampsl

zhengruifeng commented on code in PR #39469:
URL: https://github.com/apache/spark/pull/39469#discussion_r1065703462


##########
python/pyspark/sql/connect/session.py:
##########
@@ -215,7 +215,31 @@ def createDataFrame(
         _inferred_schema: Optional[StructType] = None
 
         if isinstance(data, pd.DataFrame):
-            _table = pa.Table.from_pandas(data)
+            from pandas.api.types import (  # type: ignore[attr-defined]
+                is_datetime64_dtype,
+                is_datetime64tz_dtype,
+            )
+
+            # We need double conversions for the truncation, first truncate to microseconds.
+            for col in data:
+                print("Checking", col)
+                if is_datetime64tz_dtype(data[col].dtype):
+                    data[col] = data[col].astype("datetime64[us, UTC]")
+                elif is_datetime64_dtype(data[col].dtype):
+                    data[col] = data[col].astype("datetime64[us]")
+
+            # Create a new schema and change the types to the truncated microseconds.
+            pd_schema = pa.Schema.from_pandas(data)

Review Comment:
   just for my understanding, why we need to create the pyarrow schema here?   the Pandas DataFrame datatypes had already been modified above.



-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org