This is an automated email from the ASF dual-hosted git repository.

ueshin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 255d86f  [SPARK-36940][PYTHON] Inline type hints for 
python/pyspark/sql/avro/functions.py
255d86f is described below

commit 255d86f854773c8134dc2c12e1cdcfe12aed55c1
Author: Xinrong Meng <[email protected]>
AuthorDate: Thu Oct 7 11:20:28 2021 -0700

    [SPARK-36940][PYTHON] Inline type hints for 
python/pyspark/sql/avro/functions.py
    
    ### What changes were proposed in this pull request?
    Inline type hints for python/pyspark/sql/avro/functions.py.
    
    ### Why are the changes needed?
    Currently, we use stub files for type annotations, which don't support type 
checks within function bodies. So we propose to inline the type hints to 
support that.
    
    ### Does this PR introduce _any_ user-facing change?
    No.
    
    ### How was this patch tested?
    Existing tests.
    
    Closes #34200 from xinrong-databricks/inline_avro_func.
    
    Authored-by: Xinrong Meng <[email protected]>
    Signed-off-by: Takuya UESHIN <[email protected]>
---
 python/pyspark/sql/avro/functions.py  | 20 +++++++++++++-------
 python/pyspark/sql/avro/functions.pyi | 27 ---------------------------
 2 files changed, 13 insertions(+), 34 deletions(-)

diff --git a/python/pyspark/sql/avro/functions.py 
b/python/pyspark/sql/avro/functions.py
index dbb8ab4..27d2887 100644
--- a/python/pyspark/sql/avro/functions.py
+++ b/python/pyspark/sql/avro/functions.py
@@ -20,12 +20,18 @@ A collections of builtin avro functions
 """
 
 
+from typing import Dict, Optional, TYPE_CHECKING
 from pyspark import SparkContext
-from pyspark.sql.column import Column, _to_java_column
-from pyspark.util import _print_missing_jar
+from pyspark.sql.column import Column, _to_java_column  # type: 
ignore[attr-defined]
+from pyspark.util import _print_missing_jar  # type: ignore[attr-defined]
 
+if TYPE_CHECKING:
+    from pyspark.sql._typing import ColumnOrName
 
-def from_avro(data, jsonFormatSchema, options=None):
+
+def from_avro(
+    data: "ColumnOrName", jsonFormatSchema: str, options: Optional[Dict[str, 
str]] = None
+) -> Column:
     """
     Converts a binary column of Avro format into its corresponding catalyst 
value.
     The specified schema must match the read data, otherwise the behavior is 
undefined:
@@ -67,7 +73,7 @@ def from_avro(data, jsonFormatSchema, options=None):
     [Row(value=Row(avro=Row(age=2, name='Alice')))]
     """
 
-    sc = SparkContext._active_spark_context
+    sc = SparkContext._active_spark_context  # type: ignore[attr-defined]
     try:
         jc = sc._jvm.org.apache.spark.sql.avro.functions.from_avro(
             _to_java_column(data), jsonFormatSchema, options or {})
@@ -78,7 +84,7 @@ def from_avro(data, jsonFormatSchema, options=None):
     return Column(jc)
 
 
-def to_avro(data, jsonFormatSchema=""):
+def to_avro(data: "ColumnOrName", jsonFormatSchema: str = "") -> Column:
     """
     Converts a column into binary of avro format.
 
@@ -111,7 +117,7 @@ def to_avro(data, jsonFormatSchema=""):
     [Row(suite=bytearray(b'\\x02\\x00'))]
     """
 
-    sc = SparkContext._active_spark_context
+    sc = SparkContext._active_spark_context  # type: ignore[attr-defined]
     try:
         if jsonFormatSchema == "":
             jc = 
sc._jvm.org.apache.spark.sql.avro.functions.to_avro(_to_java_column(data))
@@ -125,7 +131,7 @@ def to_avro(data, jsonFormatSchema=""):
     return Column(jc)
 
 
-def _test():
+def _test() -> None:
     import os
     import sys
     from pyspark.testing.utils import search_jar
diff --git a/python/pyspark/sql/avro/functions.pyi 
b/python/pyspark/sql/avro/functions.pyi
deleted file mode 100644
index 4988133..0000000
--- a/python/pyspark/sql/avro/functions.pyi
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# 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.
-
-from typing import Dict, Optional
-
-from pyspark.sql._typing import ColumnOrName
-from pyspark.sql.column import Column
-
-def from_avro(
-    data: ColumnOrName, jsonFormatSchema: str, options: Optional[Dict[str, 
str]] = ...
-) -> Column: ...
-def to_avro(data: ColumnOrName, jsonFormatSchema: str = ...) -> Column: ...

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

Reply via email to