You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "xinrong-meng (via GitHub)" <gi...@apache.org> on 2024/10/16 07:00:33 UTC

[PR] [WIP][SPARK-49530][PYTHON][CONNECT] Support kde/density plots [spark]

xinrong-meng opened a new pull request, #48492:
URL: https://github.com/apache/spark/pull/48492

   ### What changes were proposed in this pull request?
   Support kde/density plots with plotly backend on both Spark Connect and Spark classic.
   
   
   ### Why are the changes needed?
   While Pandas on Spark supports plotting, PySpark currently lacks this feature. The proposed API will enable users to generate visualizations. This will provide users with an intuitive, interactive way to explore and understand large datasets directly from PySpark DataFrames, streamlining the data analysis workflow in distributed environments.
   
   See more at [PySpark Plotting API Specification](https://docs.google.com/document/d/1IjOEzC8zcetG86WDvqkereQPj_NGLNW7Bdu910g30Dg/edit?usp=sharing) in progress.
   
   Part of https://issues.apache.org/jira/browse/SPARK-49530.
   
   ### Does this PR introduce _any_ user-facing change?
   Yes. Box plots are supported as shown below.
   
   ```py
   >>> data = [
   ...     (1.0, 4.0),
   ...     (2.0, 4.0),
   ...     (2.5, 4.5),
   ...     (3.0, 5.0),
   ...     (3.5, 5.5),
   ...     (4.0, 6.0),
   ...     (5.0, 6.0)
   ... ]
   >>> columns = ["x", "y"]
   >>> df = spark.createDataFrame(data, columns)
   >>> fig1 = df.plot.kde(column=["x", "y"], bw_method=0.3, ind=5)
   >>> fig1.show()  # see below
   >>> fig2 = df.plot(kind="kde", column="x", bw_method=0.3, ind=5)
   >>> fig2.show()  # see below
   ```
   
   fig1:
   ![newplot (20)](https://github.com/user-attachments/assets/d5aa8b57-b435-4a66-9e25-f37bb77f7fd8)
   
   fig2:
   ![newplot (21)](https://github.com/user-attachments/assets/3189417b-2739-485e-9c71-ff48d2c19964)
   
   
   
   ### How was this patch tested?
   Unit 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


Re: [PR] [SPARK-49530][PYTHON][CONNECT] Support kde/density plots [spark]

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

   Thank you @zhengruifeng !


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


Re: [PR] [SPARK-49530][PYTHON][CONNECT] Support kde/density plots [spark]

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

   merged 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


Re: [PR] [SPARK-49530][PYTHON][CONNECT] Support kde/density plots [spark]

Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on code in PR #48492:
URL: https://github.com/apache/spark/pull/48492#discussion_r1805745663


##########
python/pyspark/sql/pandas/utils.py:
##########
@@ -94,3 +94,33 @@ def require_minimum_pyarrow_version() -> None:
             errorClass="ARROW_LEGACY_IPC_FORMAT",
             messageParameters={},
         )
+
+
+def require_minimum_numpy_version() -> None:
+    """Raise ImportError if minimum version of NumPy is not installed"""

Review Comment:
   Good point! Created https://issues.apache.org/jira/browse/SPARK-50020 as a followup.



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


Re: [PR] [SPARK-49530][PYTHON][CONNECT] Support kde/density plots [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng closed pull request #48492: [SPARK-49530][PYTHON][CONNECT] Support kde/density plots
URL: https://github.com/apache/spark/pull/48492


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


Re: [PR] [SPARK-49530][PYTHON][CONNECT] Support kde/density plots [spark]

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

   @zhengruifeng @HyukjinKwon may I get a review please?


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


Re: [PR] [WIP][SPARK-49530][PYTHON][CONNECT] Support kde/density plots [spark]

Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on code in PR #48492:
URL: https://github.com/apache/spark/pull/48492#discussion_r1804042971


##########
python/pyspark/sql/plot/core.py:
##########
@@ -388,6 +396,127 @@ def box(
         """
         return self(kind="box", column=column, precision=precision, **kwargs)
 
+    def kde(
+        self,
+        column: Union[str, List[str]],

Review Comment:
   Create https://issues.apache.org/jira/browse/SPARK-49999 for a follow-up on optional "column" parameter support in box, kde and hist plots



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


Re: [PR] [WIP][SPARK-49530][PYTHON][CONNECT] Support kde/density plots [spark]

Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on code in PR #48492:
URL: https://github.com/apache/spark/pull/48492#discussion_r1804043756


##########
python/pyspark/sql/plot/core.py:
##########
@@ -388,6 +396,127 @@ def box(
         """
         return self(kind="box", column=column, precision=precision, **kwargs)
 
+    def kde(
+        self,
+        column: Union[str, List[str]],

Review Comment:
   Create https://issues.apache.org/jira/browse/SPARK-50000 for  optional "bw_method" in both Pandas on Spark and PySpark



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


Re: [PR] [SPARK-49530][PYTHON][CONNECT] Support kde/density plots [spark]

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


##########
python/pyspark/sql/pandas/utils.py:
##########
@@ -94,3 +94,33 @@ def require_minimum_pyarrow_version() -> None:
             errorClass="ARROW_LEGACY_IPC_FORMAT",
             messageParameters={},
         )
+
+
+def require_minimum_numpy_version() -> None:
+    """Raise ImportError if minimum version of NumPy is not installed"""

Review Comment:
   numpy is a dependency of pandas, so it is available in connect;
   but not a mandatary one in classic.
   
   It seems `kde` actually only need `np.linspace`, whose logic is not complex, so we may remove the direct dependency of `numpy` later,



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