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 13:18:02 UTC

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

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


##########
python/pyspark/sql/tests/connect/test_connect_basic.py:
##########
@@ -1071,6 +1071,25 @@ def test_to_pandas(self):
             self.spark.sql(query).toPandas(),
         )
 
+    def test_create_dataframe_from_pandas_with_ns_timestamp(self):
+        """Truncate the timestamps for nanoseconds."""
+        from datetime import datetime, timezone, timedelta
+        from pandas import Timestamp
+        import pandas as pd
+
+        pdf = pd.DataFrame(
+            {
+                "naive": [datetime(2019, 1, 1, 0)],
+                "aware": [
+                    Timestamp(
+                        year=2019, month=1, day=1, nanosecond=1, tz=timezone(timedelta(hours=-8))
+                    )
+                ],
+            }
+        )
+        rows = self.connect.createDataFrame(pdf).collect()
+        self.assertEqual(1, len(rows))

Review Comment:
   Fixed by comparing the full result.



##########
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)

Review Comment:
   Removed



-- 
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