Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-36708][PYTHON] Support numpy.typing for annotating ArrayType i…
…n pandas API on Spark ### What changes were proposed in this pull request? This PR adds the support of understanding `numpy.typing` package that's added from NumPy 1.21. ### Why are the changes needed? For user-friendly return type specification in type hints for function apply APIs in pandas API on Spark. ### Does this PR introduce _any_ user-facing change? Yes, this PR will enable users to specify return type as `numpy.typing.NDArray[...]` to internally specify pandas UDF's return type. For example, ```python import pandas as pd import pyspark.pandas as ps pdf = pd.DataFrame( {"a": [1, 2, 3, 4, 5, 6, 7, 8, 9], "b": [[e] for e in [4, 5, 6, 3, 2, 1, 0, 0, 0]]}, index=np.random.rand(9), ) psdf = ps.from_pandas(pdf) def func(x) -> ps.DataFrame[float, [int, ntp.NDArray[int]]]: return x psdf.pandas_on_spark.apply_batch(func) ``` ### How was this patch tested? Unittest and e2e tests were added. Closes #34028 from HyukjinKwon/SPARK-36708. Authored-by: Hyukjin Kwon <gurwls223@apache.org> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
- Loading branch information
1 parent
6a5ee02
commit cc2fcb4
Showing
3 changed files
with
68 additions
and
24 deletions.
There are no files selected for viewing
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
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
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