Skip to content

[SPARK-50054][PYTHON][CONNECT] Support histogram plots#48578

Closed
xinrong-meng wants to merge 4 commits intoapache:masterfrom
xinrong-meng:histogram
Closed

[SPARK-50054][PYTHON][CONNECT] Support histogram plots#48578
xinrong-meng wants to merge 4 commits intoapache:masterfrom
xinrong-meng:histogram

Conversation

@xinrong-meng
Copy link
Member

@xinrong-meng xinrong-meng commented Oct 21, 2024

What changes were proposed in this pull request?

Support histogram 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 in progress.

Part of https://issues.apache.org/jira/browse/SPARK-49530.

Does this PR introduce any user-facing change?

Yes. Histogram plots are supported as shown below.

>>> data = [(5.1, 3.5, 0), (4.9, 3.0, 0), (7.0, 3.2, 1), (6.4, 3.2, 1), (5.9, 3.0, 2)]
>>> columns = ["length", "width", "species"]
>>> df = spark.createDataFrame(data, columns)
>>> fig1 = df.plot.hist(column=['length','width'], bins=4)
>>> fig1.show()  # see below
>>> fig2 = df.plot(kind="hist",column='length', bins=4)
>>> fig2.show()  # see below

fig1:
newplot (24)

fig2:
newplot (25)

How was this patch tested?

Unit tests.

Was this patch authored or co-authored using generative AI tooling?

No.

@xinrong-meng xinrong-meng changed the title [WIP][SPARK-50054][PYTHON][CONNECT] Support histogram plots [SPARK-50054][PYTHON][CONNECT] Support histogram plots Oct 22, 2024
@xinrong-meng xinrong-meng marked this pull request as ready for review October 22, 2024 02:23
@xinrong-meng
Copy link
Member Author

The logic for constructing the histogram is mostly copied from Pandas on Spark to maintain parity. We can refactor it for reuse in a follow-up.

@xinrong-meng
Copy link
Member Author

@zhengruifeng @HyukjinKwon may I get a review please?

@zhengruifeng
Copy link
Contributor

merged to master

ericm-db pushed a commit to ericm-db/spark that referenced this pull request Oct 22, 2024
### What changes were proposed in this pull request?
Support histogram 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. Histogram plots are supported as shown below.

```py
>>> data = [(5.1, 3.5, 0), (4.9, 3.0, 0), (7.0, 3.2, 1), (6.4, 3.2, 1), (5.9, 3.0, 2)]
>>> columns = ["length", "width", "species"]
>>> df = spark.createDataFrame(data, columns)
>>> fig1 = df.plot.hist(column=['length','width'], bins=4)
>>> fig1.show()  # see below
>>> fig2 = df.plot(kind="hist",column='length', bins=4)
>>> fig2.show()  # see below
```

fig1:
![newplot (24)](https://github.com/user-attachments/assets/9d792fc9-e303-4257-a093-1d3c55a12a31)

fig2:
![newplot (25)](https://github.com/user-attachments/assets/0a4a4cfa-9f79-4431-b287-e7fe2f93cf69)

### How was this patch tested?
Unit tests.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes apache#48578 from xinrong-meng/histogram.

Authored-by: Xinrong Meng <xinrong@apache.org>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
@xinrong-meng
Copy link
Member Author

Thank you @zhengruifeng !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants