-
Notifications
You must be signed in to change notification settings - Fork 28.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-45988][SPARK-45989][PYTHON] Fix typehints to handle list
GenericAlias in Python 3.11+
#43888
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dongjoon-hyun
force-pushed
the
SPARK-45988
branch
from
November 19, 2023 10:48
8cbde36
to
e2a8c50
Compare
HyukjinKwon
approved these changes
Nov 19, 2023
Thanks for fixing this!! |
Merged to master! |
Thank you so much, @HyukjinKwon ! |
late LGTM, thanks |
Let me backport this to branch-3.5 as well. |
HyukjinKwon
pushed a commit
that referenced
this pull request
May 2, 2024
…ericAlias in Python 3.11+ ### What changes were proposed in this pull request? This PR aims to fix `type hints` to handle `list` GenericAlias in Python 3.11+ for Apache Spark 4.0.0 and 3.5.1. - https://github.com/apache/spark/actions/workflows/build_python.yml ### Why are the changes needed? PEP 646 changes `GenericAlias` instances into `Iterable` ones at Python 3.11. - https://peps.python.org/pep-0646/ This behavior changes introduce the following failure on Python 3.11. - **Python 3.11.6** ```python Python 3.11.6 (main, Nov 1 2023, 07:46:30) [Clang 14.0.0 (clang-1400.0.28.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). 23/11/18 16:34:09 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /__ / .__/\_,_/_/ /_/\_\ version 3.5.0 /_/ Using Python version 3.11.6 (main, Nov 1 2023 07:46:30) Spark context Web UI available at http://localhost:4040 Spark context available as 'sc' (master = local[*], app id = local-1700354049391). SparkSession available as 'spark'. >>> from pyspark import pandas as ps >>> from typing import List >>> ps.DataFrame[float, [int, List[int]]] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/frame.py", line 13647, in __class_getitem__ return create_tuple_for_frame_type(params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/typedef/typehints.py", line 717, in create_tuple_for_frame_type return Tuple[_to_type_holders(params)] ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/typedef/typehints.py", line 762, in _to_type_holders data_types = _new_type_holders(data_types, NameTypeHolder) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/typedef/typehints.py", line 828, in _new_type_holders raise TypeError( TypeError: Type hints should be specified as one of: - DataFrame[type, type, ...] - DataFrame[name: type, name: type, ...] - DataFrame[dtypes instance] - DataFrame[zip(names, types)] - DataFrame[index_type, [type, ...]] - DataFrame[(index_name, index_type), [(name, type), ...]] - DataFrame[dtype instance, dtypes instance] - DataFrame[(index_name, index_type), zip(names, types)] - DataFrame[[index_type, ...], [type, ...]] - DataFrame[[(index_name, index_type), ...], [(name, type), ...]] - DataFrame[dtypes instance, dtypes instance] - DataFrame[zip(index_names, index_types), zip(names, types)] However, got (<class 'int'>, typing.List[int]). ``` - **Python 3.10.13** ```python Python 3.10.13 (main, Sep 29 2023, 16:03:45) [Clang 14.0.0 (clang-1400.0.28.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). 23/11/18 16:33:21 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /__ / .__/\_,_/_/ /_/\_\ version 3.5.0 /_/ Using Python version 3.10.13 (main, Sep 29 2023 16:03:45) Spark context Web UI available at http://localhost:4040 Spark context available as 'sc' (master = local[*], app id = local-1700354002048). SparkSession available as 'spark'. >>> from pyspark import pandas as ps >>> from typing import List >>> ps.DataFrame[float, [int, List[int]]] typing.Tuple[pyspark.pandas.typedef.typehints.IndexNameType, pyspark.pandas.typedef.typehints.NameType, pyspark.pandas.typedef.typehints.NameType] >>> ``` ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass the CIs. Manually test with Python 3.11. ``` $ build/sbt -Phadoop-3 -Pkinesis-asl -Pyarn -Pkubernetes -Pdocker-integration-tests -Pconnect -Pspark-ganglia-lgpl -Pvolcano -Phadoop-cloud -Phive-thriftserver -Phive Test/package streaming-kinesis-asl-assembly/assembly connect/assembly $ python/run-tests --modules pyspark-pandas-slow --python-executables python3.11 ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #43888 from dongjoon-hyun/SPARK-45988. Authored-by: Dongjoon Hyun <dhyun@apple.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
Thank you, @HyukjinKwon ! |
dongjoon-hyun
added a commit
that referenced
this pull request
May 2, 2024
…ericAlias in Python 3.11+ ### What changes were proposed in this pull request? This PR aims to fix `type hints` to handle `list` GenericAlias in Python 3.11+ for Apache Spark 4.0.0 and 3.5.1. - https://github.com/apache/spark/actions/workflows/build_python.yml ### Why are the changes needed? PEP 646 changes `GenericAlias` instances into `Iterable` ones at Python 3.11. - https://peps.python.org/pep-0646/ This behavior changes introduce the following failure on Python 3.11. - **Python 3.11.6** ```python Python 3.11.6 (main, Nov 1 2023, 07:46:30) [Clang 14.0.0 (clang-1400.0.28.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). 23/11/18 16:34:09 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /__ / .__/\_,_/_/ /_/\_\ version 3.5.0 /_/ Using Python version 3.11.6 (main, Nov 1 2023 07:46:30) Spark context Web UI available at http://localhost:4040 Spark context available as 'sc' (master = local[*], app id = local-1700354049391). SparkSession available as 'spark'. >>> from pyspark import pandas as ps >>> from typing import List >>> ps.DataFrame[float, [int, List[int]]] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/frame.py", line 13647, in __class_getitem__ return create_tuple_for_frame_type(params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/typedef/typehints.py", line 717, in create_tuple_for_frame_type return Tuple[_to_type_holders(params)] ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/typedef/typehints.py", line 762, in _to_type_holders data_types = _new_type_holders(data_types, NameTypeHolder) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/typedef/typehints.py", line 828, in _new_type_holders raise TypeError( TypeError: Type hints should be specified as one of: - DataFrame[type, type, ...] - DataFrame[name: type, name: type, ...] - DataFrame[dtypes instance] - DataFrame[zip(names, types)] - DataFrame[index_type, [type, ...]] - DataFrame[(index_name, index_type), [(name, type), ...]] - DataFrame[dtype instance, dtypes instance] - DataFrame[(index_name, index_type), zip(names, types)] - DataFrame[[index_type, ...], [type, ...]] - DataFrame[[(index_name, index_type), ...], [(name, type), ...]] - DataFrame[dtypes instance, dtypes instance] - DataFrame[zip(index_names, index_types), zip(names, types)] However, got (<class 'int'>, typing.List[int]). ``` - **Python 3.10.13** ```python Python 3.10.13 (main, Sep 29 2023, 16:03:45) [Clang 14.0.0 (clang-1400.0.28.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). 23/11/18 16:33:21 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /__ / .__/\_,_/_/ /_/\_\ version 3.5.0 /_/ Using Python version 3.10.13 (main, Sep 29 2023 16:03:45) Spark context Web UI available at http://localhost:4040 Spark context available as 'sc' (master = local[*], app id = local-1700354002048). SparkSession available as 'spark'. >>> from pyspark import pandas as ps >>> from typing import List >>> ps.DataFrame[float, [int, List[int]]] typing.Tuple[pyspark.pandas.typedef.typehints.IndexNameType, pyspark.pandas.typedef.typehints.NameType, pyspark.pandas.typedef.typehints.NameType] >>> ``` ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass the CIs. Manually test with Python 3.11. ``` $ build/sbt -Phadoop-3 -Pkinesis-asl -Pyarn -Pkubernetes -Pdocker-integration-tests -Pconnect -Pspark-ganglia-lgpl -Pvolcano -Phadoop-cloud -Phive-thriftserver -Phive Test/package streaming-kinesis-asl-assembly/assembly connect/assembly $ python/run-tests --modules pyspark-pandas-slow --python-executables python3.11 ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #43888 from dongjoon-hyun/SPARK-45988. Authored-by: Dongjoon Hyun <dhyun@apple.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
I also cherry-picked it to branch-3.4, too |
szehon-ho
pushed a commit
to szehon-ho/spark
that referenced
this pull request
Aug 7, 2024
…ericAlias in Python 3.11+ ### What changes were proposed in this pull request? This PR aims to fix `type hints` to handle `list` GenericAlias in Python 3.11+ for Apache Spark 4.0.0 and 3.5.1. - https://github.com/apache/spark/actions/workflows/build_python.yml ### Why are the changes needed? PEP 646 changes `GenericAlias` instances into `Iterable` ones at Python 3.11. - https://peps.python.org/pep-0646/ This behavior changes introduce the following failure on Python 3.11. - **Python 3.11.6** ```python Python 3.11.6 (main, Nov 1 2023, 07:46:30) [Clang 14.0.0 (clang-1400.0.28.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). 23/11/18 16:34:09 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /__ / .__/\_,_/_/ /_/\_\ version 3.5.0 /_/ Using Python version 3.11.6 (main, Nov 1 2023 07:46:30) Spark context Web UI available at http://localhost:4040 Spark context available as 'sc' (master = local[*], app id = local-1700354049391). SparkSession available as 'spark'. >>> from pyspark import pandas as ps >>> from typing import List >>> ps.DataFrame[float, [int, List[int]]] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/frame.py", line 13647, in __class_getitem__ return create_tuple_for_frame_type(params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/typedef/typehints.py", line 717, in create_tuple_for_frame_type return Tuple[_to_type_holders(params)] ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/typedef/typehints.py", line 762, in _to_type_holders data_types = _new_type_holders(data_types, NameTypeHolder) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dongjoon/APACHE/spark-release/spark-3.5.0-bin-hadoop3/python/pyspark/pandas/typedef/typehints.py", line 828, in _new_type_holders raise TypeError( TypeError: Type hints should be specified as one of: - DataFrame[type, type, ...] - DataFrame[name: type, name: type, ...] - DataFrame[dtypes instance] - DataFrame[zip(names, types)] - DataFrame[index_type, [type, ...]] - DataFrame[(index_name, index_type), [(name, type), ...]] - DataFrame[dtype instance, dtypes instance] - DataFrame[(index_name, index_type), zip(names, types)] - DataFrame[[index_type, ...], [type, ...]] - DataFrame[[(index_name, index_type), ...], [(name, type), ...]] - DataFrame[dtypes instance, dtypes instance] - DataFrame[zip(index_names, index_types), zip(names, types)] However, got (<class 'int'>, typing.List[int]). ``` - **Python 3.10.13** ```python Python 3.10.13 (main, Sep 29 2023, 16:03:45) [Clang 14.0.0 (clang-1400.0.28.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). 23/11/18 16:33:21 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /__ / .__/\_,_/_/ /_/\_\ version 3.5.0 /_/ Using Python version 3.10.13 (main, Sep 29 2023 16:03:45) Spark context Web UI available at http://localhost:4040 Spark context available as 'sc' (master = local[*], app id = local-1700354002048). SparkSession available as 'spark'. >>> from pyspark import pandas as ps >>> from typing import List >>> ps.DataFrame[float, [int, List[int]]] typing.Tuple[pyspark.pandas.typedef.typehints.IndexNameType, pyspark.pandas.typedef.typehints.NameType, pyspark.pandas.typedef.typehints.NameType] >>> ``` ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass the CIs. Manually test with Python 3.11. ``` $ build/sbt -Phadoop-3 -Pkinesis-asl -Pyarn -Pkubernetes -Pdocker-integration-tests -Pconnect -Pspark-ganglia-lgpl -Pvolcano -Phadoop-cloud -Phive-thriftserver -Phive Test/package streaming-kinesis-asl-assembly/assembly connect/assembly $ python/run-tests --modules pyspark-pandas-slow --python-executables python3.11 ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#43888 from dongjoon-hyun/SPARK-45988. Authored-by: Dongjoon Hyun <dhyun@apple.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org> (cherry picked from commit a75c93b)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR aims to fix
type hints
to handlelist
GenericAlias in Python 3.11+ for Apache Spark 4.0.0 and 3.5.1.Why are the changes needed?
PEP 646 changes
GenericAlias
instances intoIterable
ones at Python 3.11.This behavior changes introduce the following failure on Python 3.11.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Pass the CIs. Manually test with Python 3.11.
Was this patch authored or co-authored using generative AI tooling?
No.