You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "ueshin (via GitHub)" <gi...@apache.org> on 2023/09/11 20:28:54 UTC

[GitHub] [spark] ueshin opened a new pull request, #42874: [SPARK-45118][PYTHON] Refactor converters for complex types to short cut when the element types don't need converters

ueshin opened a new pull request, #42874:
URL: https://github.com/apache/spark/pull/42874

   ### What changes were proposed in this pull request?
   
   Refactors converters for complex types to short cut when the element types don't need converters.
   
   The following refactors are done in this PR:
   
   - Provide a shortcut when the element types in complex types don't need converters
   - Check `None`s before calling the converter
   - Remove extra type checks just for assertions
   
   ### Why are the changes needed?
   
   When the element types in complex types don't need converters, we can provide a shortcut to avoid extra function calls.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   Added related tests and existing tests.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No.


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


[GitHub] [spark] ueshin commented on a diff in pull request #42874: [SPARK-45118][PYTHON] Refactor converters for complex types to short cut when the element types don't need converters

Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on code in PR #42874:
URL: https://github.com/apache/spark/pull/42874#discussion_r1323586402


##########
python/pyspark/sql/pandas/types.py:
##########
@@ -793,51 +851,94 @@ def correct_timestamp(pser: pd.Series) -> pd.Series:
     def _converter(dt: DataType) -> Optional[Callable[[Any], Any]]:
 
         if isinstance(dt, ArrayType):
-            _element_conv = _converter(dt.elementType) or (lambda x: x)

Review Comment:
   Yes, it's from the unnecessary lambda function.



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


[GitHub] [spark] ueshin commented on a diff in pull request #42874: [SPARK-45118][PYTHON] Refactor converters for complex types to short cut when the element types don't need converters

Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on code in PR #42874:
URL: https://github.com/apache/spark/pull/42874#discussion_r1323586402


##########
python/pyspark/sql/pandas/types.py:
##########
@@ -793,51 +851,94 @@ def correct_timestamp(pser: pd.Series) -> pd.Series:
     def _converter(dt: DataType) -> Optional[Callable[[Any], Any]]:
 
         if isinstance(dt, ArrayType):
-            _element_conv = _converter(dt.elementType) or (lambda x: x)

Review Comment:
   Yes, it's from the unnecessary lambda function call.



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


[GitHub] [spark] ueshin commented on pull request #42874: [SPARK-45118][PYTHON] Refactor converters for complex types to short cut when the element types don't need converters

Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on PR #42874:
URL: https://github.com/apache/spark/pull/42874#issuecomment-1718070979

   The test failure is from `ReattachableExecuteSuite`. I don't think it's related to this PR.


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


[GitHub] [spark] ueshin closed pull request #42874: [SPARK-45118][PYTHON] Refactor converters for complex types to short cut when the element types don't need converters

Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin closed pull request #42874: [SPARK-45118][PYTHON] Refactor converters for complex types to short cut when the element types don't need converters
URL: https://github.com/apache/spark/pull/42874


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


[GitHub] [spark] allisonwang-db commented on a diff in pull request #42874: [SPARK-45118][PYTHON] Refactor converters for complex types to short cut when the element types don't need converters

Posted by "allisonwang-db (via GitHub)" <gi...@apache.org>.
allisonwang-db commented on code in PR #42874:
URL: https://github.com/apache/spark/pull/42874#discussion_r1323509342


##########
python/pyspark/sql/tests/pandas/test_types.py:
##########
@@ -0,0 +1,595 @@
+#
+# 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 unittest
+from typing import cast
+
+from pyspark.sql.types import (
+    ArrayType,
+    IntegerType,
+    MapType,
+    StringType,
+    StructType,
+    Row,
+)
+from pyspark.testing.sqlutils import (
+    have_pandas,
+    have_pyarrow,
+    pandas_requirement_message,
+    pyarrow_requirement_message,
+)
+
+if have_pandas:
+    import pandas as pd
+    import numpy as np
+
+    from pandas.testing import assert_series_equal
+    from pyspark.sql.pandas.types import _create_converter_from_pandas, _create_converter_to_pandas
+
+if have_pyarrow:
+    import pyarrow as pa  # noqa: F401
+
+
+@unittest.skipIf(
+    not have_pandas or not have_pyarrow,
+    cast(str, pandas_requirement_message or pyarrow_requirement_message),
+)
+class TypesTests(unittest.TestCase):

Review Comment:
   Shall we call this ConverterTests?



##########
python/pyspark/sql/pandas/types.py:
##########
@@ -793,51 +851,94 @@ def correct_timestamp(pser: pd.Series) -> pd.Series:
     def _converter(dt: DataType) -> Optional[Callable[[Any], Any]]:
 
         if isinstance(dt, ArrayType):
-            _element_conv = _converter(dt.elementType) or (lambda x: x)

Review Comment:
   Does the performance overhead come from this lambda function? Or does it come from this if statement:
   ```
   def convert_xxx:
       if value is None:
           return None
   ```



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


[GitHub] [spark] ueshin commented on pull request #42874: [SPARK-45118][PYTHON] Refactor converters for complex types to short cut when the element types don't need converters

Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on PR #42874:
URL: https://github.com/apache/spark/pull/42874#issuecomment-1719881732

   Thanks! merging to master.


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