You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/12/15 18:39:30 UTC

[GitHub] [spark] zero323 commented on a change in pull request #34892: [SPARK-37620][PYTHON] Use more precise types for SparkContext Optional fields (i.e. _gateway, _jvm)

zero323 commented on a change in pull request #34892:
URL: https://github.com/apache/spark/pull/34892#discussion_r769897401



##########
File path: python/pyspark/sql/functions.py
##########
@@ -1081,7 +1081,9 @@ def approx_count_distinct(col: "ColumnOrName", rsd: Optional[float] = None) -> C
     >>> df.agg(approx_count_distinct(df.age).alias('distinct_ages')).collect()
     [Row(distinct_ages=2)]
     """
-    sc = SparkContext._active_spark_context  # type: ignore[attr-defined]
+    sc = SparkContext._active_spark_context
+    assert sc is not None
+    assert sc._jvm is not None

Review comment:
       Nit: (I don't have strong feelings about it)  Doing this in a single line should work just fine and be preferable in the future:
   
   ```python
       assert sc is not None and sc._jvm is not 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