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/12/23 08:31:14 UTC
[PR] [SPARK-49530][PYTHON] Support pie subplots in pyspark plotting [spark]
xinrong-meng opened a new pull request, #49268:
URL: https://github.com/apache/spark/pull/49268
### What changes were proposed in this pull request?
Support pie subplots in pyspark plotting.
### Why are the changes needed?
API parity with pandas.DataFrame.plot.pie, see [here](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.pie.html)
### Does this PR introduce _any_ user-facing change?
Pie subplots are supported as shown below:
```py
>>> from datetime import datetime
>>> data = [
... (3, 5, 20, datetime(2018, 1, 31)),
... (2, 5, 42, datetime(2018, 2, 28)),
... (3, 6, 28, datetime(2018, 3, 31)),
... (9, 12, 62, datetime(2018, 4, 30)),
... ]
>>> columns = ["sales", "signups", "visits", "date"]
>>> df = spark.createDataFrame(data, columns)
>>> fig = df.plot(kind="pie", x="date", subplots=True)
>>> fig.show()
```

### 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] Support pie subplots in pyspark plotting [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #49268: [SPARK-49530][PYTHON] Support pie subplots in pyspark plotting
URL: https://github.com/apache/spark/pull/49268
--
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] Support pie subplots in pyspark plotting [spark]
Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on PR #49268:
URL: https://github.com/apache/spark/pull/49268#issuecomment-2562193541
Thank you @HyukjinKwon !
--
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] Support pie subplots in pyspark plotting [spark]
Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on code in PR #49268:
URL: https://github.com/apache/spark/pull/49268#discussion_r1897660935
##########
python/pyspark/sql/plot/plotly.py:
##########
@@ -48,13 +48,34 @@ def plot_pyspark(data: "DataFrame", kind: str, **kwargs: Any) -> "Figure":
def plot_pie(data: "DataFrame", **kwargs: Any) -> "Figure":
- # TODO(SPARK-49530): Support pie subplots with plotly backend
from plotly import express
pdf = PySparkPlotAccessor.plot_data_map["pie"](data)
x = kwargs.pop("x", None)
y = kwargs.pop("y", None)
- fig = express.pie(pdf, values=y, names=x, **kwargs)
+ subplots = kwargs.pop("subplots", False)
+ if y is None and not subplots:
+ raise PySparkValueError(errorClass="UNSUPPORTED_PIE_PLOT_PARAM", messageParameters={})
Review Comment:
We are trying to reach parity with pandas [here](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.pie.html). Thanks for the feedback!
--
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] Support pie subplots in pyspark plotting [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #49268:
URL: https://github.com/apache/spark/pull/49268#issuecomment-2560482050
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] Support pie subplots in pyspark plotting [spark]
Posted by "tedyu (via GitHub)" <gi...@apache.org>.
tedyu commented on code in PR #49268:
URL: https://github.com/apache/spark/pull/49268#discussion_r1897514857
##########
python/pyspark/sql/plot/plotly.py:
##########
@@ -48,13 +48,34 @@ def plot_pyspark(data: "DataFrame", kind: str, **kwargs: Any) -> "Figure":
def plot_pie(data: "DataFrame", **kwargs: Any) -> "Figure":
- # TODO(SPARK-49530): Support pie subplots with plotly backend
from plotly import express
pdf = PySparkPlotAccessor.plot_data_map["pie"](data)
x = kwargs.pop("x", None)
y = kwargs.pop("y", None)
- fig = express.pie(pdf, values=y, names=x, **kwargs)
+ subplots = kwargs.pop("subplots", False)
+ if y is None and not subplots:
+ raise PySparkValueError(errorClass="UNSUPPORTED_PIE_PLOT_PARAM", messageParameters={})
Review Comment:
It seems we can use default value of `True` for `subplots` in this case (`y is 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
Re: [PR] [SPARK-49530][PYTHON] Support pie subplots in pyspark plotting [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #49268:
URL: https://github.com/apache/spark/pull/49268#discussion_r1896238516
##########
python/pyspark/sql/plot/core.py:
##########
@@ -306,8 +305,8 @@ def pie(self, x: str, y: str, **kwargs: Any) -> "Figure":
----------
x : str
Name of column to be used as the category labels for the pie plot.
- y : str
- Name of the column to plot.
+ y : str, optional
+ Name of the column to plot. If not provided, `subplots=True` must be passed,
Review Comment:
```suggestion
Name of the column to plot. If not provided, `subplots=True` must be passed at `kwargs`.
```
--
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