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


##########
python/pyspark/sql/tests/test_time_functions.py:
##########
@@ -0,0 +1,406 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import datetime
+import unittest
+
+from pyspark.sql import functions as F
+from pyspark.sql.types import (
+    StructField,
+    StructType,
+    TimeType,
+)
+from pyspark.errors import DateTimeException, IllegalArgumentException
+from pyspark.testing.sqlutils import ReusedSQLTestCase
+from pyspark.testing.utils import (
+    have_pandas,
+    have_pyarrow,
+    pandas_requirement_message,
+    pyarrow_requirement_message,
+)
+
+
+class TimeFunctionsTestsMixin:
+    """Tests for TIME data type functions in PySpark."""
+
+    def test_create_dataframe_roundtrip(self):
+        """Test that datetime.time values survive createDataFrame -> collect 
round-trip."""
+        data = [
+            (datetime.time(0, 0, 0),),
+            (datetime.time(12, 30, 45),),
+            (datetime.time(23, 59, 59, 999999),),
+            (None,),
+        ]
+        schema = StructType([StructField("t", TimeType())])
+        df = self.spark.createDataFrame(data, schema=schema)
+
+        result = df.collect()
+        self.assertEqual(result[0].t, datetime.time(0, 0, 0))
+        self.assertEqual(result[1].t, datetime.time(12, 30, 45))
+        self.assertEqual(result[2].t, datetime.time(23, 59, 59, 999999))
+        self.assertIsNone(result[3].t)
+
+    def test_create_dataframe_infer_schema(self):
+        """Test that schema inference recognizes datetime.time as TimeType."""
+        data = [(datetime.time(10, 30),), (datetime.time(14, 0),)]
+        df = self.spark.createDataFrame(data, ["t"])
+        self.assertIsInstance(df.schema["t"].dataType, TimeType)
+
+    def test_make_time(self):
+        """Test make_time function with various inputs."""
+        df = self.spark.createDataFrame([(10, 30, 45), (23, 59, 59)], ["h", 
"m", "s"])
+
+        result = df.select(F.make_time("h", "m", "s")).collect()
+        self.assertEqual(result[0][0], datetime.time(10, 30, 45))
+        self.assertEqual(result[1][0], datetime.time(23, 59, 59))
+
+        # selectExpr parity
+        result_expr = df.selectExpr("make_time(h, m, s)").collect()
+        self.assertEqual(result[0][0], result_expr[0][0])
+        self.assertEqual(result[1][0], result_expr[1][0])
+
+    def test_make_time_null_handling(self):
+        """Test make_time returns NULL when any input is NULL."""
+        df = self.spark.createDataFrame(
+            [(None, 30, 45), (10, None, 45), (10, 30, None)],
+            "h: int, m: int, s: int",
+        )
+        result = df.select(F.make_time("h", "m", "s")).collect()
+        for row in result:
+            self.assertIsNone(row[0])
+
+    def test_hour(self):

Review Comment:
   for functions, we highly rely on the JVM tests - the functions in PySpark 
are mostly tested in doctests



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