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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to