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 2025/01/07 07:36:13 UTC
[PR] [WIP] Make DataFrame.plot a class variable [spark]
xinrong-meng opened a new pull request, #49394:
URL: https://github.com/apache/spark/pull/49394
### What changes were proposed in this pull request?
Make DataFrame.plot a class variable
### Why are the changes needed?
Previously
```
>>> from pyspark.sql import DataFrame
>>> DataFrame.plot
<property object at 0x10543fd60>
>>> dir(DataFrame.plot)
['__class__', '__delattr__', '__delete__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__isabstractmethod__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__set__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'deleter', 'fdel', 'fget', 'fset', 'getter', 'setter']
```
Making sphinx failed to recognize plot accessor's chaining plot methods: "bar", "barh", etc, thus, failed to populate docs for plot methods.
Compared with Pandas API on Spark
```
>>> import pyspark.pandas as ps
>>> ps.DataFrame.plot
<class 'pyspark.pandas.plot.core.PandasOnSparkPlotAccessor'>
```
We want them to reach parity.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
--
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-50753][PYTHON] Add CachedAccessor for PySpark Plotting [spark]
Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on code in PR #49394:
URL: https://github.com/apache/spark/pull/49394#discussion_r1906911125
##########
python/pyspark/sql/dataframe.py:
##########
@@ -6794,35 +6793,7 @@ def executionInfo(self) -> Optional["ExecutionInfo"]:
"""
...
- @property
- def plot(self) -> "PySparkPlotAccessor":
- """
- Returns a :class:`PySparkPlotAccessor` for plotting functions.
-
- .. versionadded:: 4.0.0
-
- Returns
- -------
- :class:`PySparkPlotAccessor`
-
- Notes
- -----
- This API is experimental.
- It provides two ways to create plots:
- 1. Chaining style (e.g., `df.plot.line(...)`).
- 2. Explicit style (e.g., `df.plot(kind="line", ...)`).
-
- Examples
- --------
- >>> data = [("A", 10, 1.5), ("B", 30, 2.5), ("C", 20, 3.5)]
- >>> columns = ["category", "int_val", "float_val"]
- >>> df = spark.createDataFrame(data, columns)
- >>> type(df.plot)
- <class 'pyspark.sql.plot.core.PySparkPlotAccessor'>
- >>> df.plot.line(x="category", y=["int_val", "float_val"]) # doctest: +SKIP
- >>> df.plot(kind="line", x="category", y=["int_val", "float_val"]) # doctest: +SKIP
- """
- ...
+ plot: CachedAccessor = CachedAccessor("plot", "pyspark.sql.plot.core.PySparkPlotAccessor")
Review Comment:
That lazy import fails doc generation
```
Warning, treated as error:
autodoc: failed to import class 'plot' from module 'DataFrame'; the following exception was raised:
No module named 'DataFrame'
make: *** [Makefile:35: html] Error 2
```
@HyukjinKwon @itholic do you happen to know how to work around this? Thank you!
--
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-50753][PYTHON] Add CachedAccessor for PySpark Plotting [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #49394:
URL: https://github.com/apache/spark/pull/49394#issuecomment-2816394749
We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable.
If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!
--
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-50753][PYTHON] Add CachedAccessor for PySpark Plotting [spark]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #49394: [SPARK-50753][PYTHON] Add CachedAccessor for PySpark Plotting
URL: https://github.com/apache/spark/pull/49394
--
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-50753][PYTHON] Add CachedAccessor for PySpark Plotting [spark]
Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on code in PR #49394:
URL: https://github.com/apache/spark/pull/49394#discussion_r1906541895
##########
python/pyspark/sql/utils.py:
##########
@@ -490,3 +492,49 @@ def remote_only(func: Union[Callable, property]) -> Union[Callable, property]:
else:
func._remote_only = True # type: ignore[attr-defined]
return func
+
+
+T = TypeVar("T")
+
+
+class CachedAccessor(Generic[T]):
Review Comment:
There will be a followup to consolidate CachedAccessors between the Pandas API on Spark and the one here
--
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