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 2022/09/28 12:36:01 UTC

[GitHub] [spark] itholic opened a new pull request, #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

itholic opened a new pull request, #38033:
URL: https://github.com/apache/spark/pull/38033

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   This PR proposes to fix the plotting functions working properly with pandas 1.5.0.
   
   This includes two fixes:
   - Fix the `PandasOnSpark*Plot` to get name of plot in the string format properly.
   - Fix the default value of `subplots` parameter from `plot_frame` to match with latest pandas. (`None` -> `False`)
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   We're leverage the pandas plotting classes to implement for `matplotlib` implementation, and get the class name from pandas like:
   ```python
   >>> from pandas.plotting._matplotlib.core import AreaPlot
   >>> AreaPlot._kind
   'area'
   ```
   However, since pandas 1.5.0, they convert `_kind` into properly, so we cannot bring the name of class properly from pandas class as below:
   ```python
   >>> from pandas.plotting._matplotlib.core import AreaPlot
   AreaPlot._kind
   >>> AreaPlot._kind
   <property object at 0x7fe520d749a0>
   ```
   
   With this fix, it work properly with pandas 1.5.0 as below:
   
   #### 1. For Series and DataFrame plot,
   
   **Before**:
   ```python
   >>> from pyspark.pandas.config import set_option
   >>> set_option("plotting.backend", "matplotlib")
   >>> import pyspark.pandas as ps
   >>> psdf = ps.range(10)
   >>> psdf.plot(kind="bar")
   Traceback (most recent call last):
   ...
   KeyError: 'bar'
   ```
   
   **After**:
   ```python
   >>> from pyspark.pandas.config import set_option
   >>> set_option("plotting.backend", "matplotlib")
   >>> import pyspark.pandas as ps
   >>> psdf = ps.range(10)
   >>> psdf.plot(kind="bar")
   <AxesSubplot:>
   ```
   
   #### 2. For DataFrame plot,
   
   **Before**:
   ```python
   >>> from pyspark.pandas.config import set_option
   >>> set_option("plotting.backend", "matplotlib")
   >>> import pyspark.pandas as ps
   >>> psdf = ps.range(10)
   >>> psdf.plot(kind="bar")
   Traceback (most recent call last):
   ...
   ValueError: subplots should be a bool or an iterable
   ```
   
   **After**:
   ```python
   >>> from pyspark.pandas.config import set_option
   >>> set_option("plotting.backend", "matplotlib")
   >>> import pyspark.pandas as ps
   >>> psdf = ps.range(10)
   >>> psdf.plot(kind="bar")
   <AxesSubplot:>
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   No
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   
   Manually tested with pandas 1.5.0.
   


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


[GitHub] [spark] xinrong-meng commented on pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

Posted by GitBox <gi...@apache.org>.
xinrong-meng commented on PR #38033:
URL: https://github.com/apache/spark/pull/38033#issuecomment-1262620351

   Shall we follow pandas to make `_kind` a `property`?


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


[GitHub] [spark] xinrong-meng commented on pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

Posted by GitBox <gi...@apache.org>.
xinrong-meng commented on PR #38033:
URL: https://github.com/apache/spark/pull/38033#issuecomment-1271025412

   Makes sense! Class member approach looks fine. Thanks for explaining that! LGTM.


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


[GitHub] [spark] zhengruifeng commented on pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

Posted by GitBox <gi...@apache.org>.
zhengruifeng commented on PR #38033:
URL: https://github.com/apache/spark/pull/38033#issuecomment-1263015696

   this regression is `matplotlib`-only? do we need to also fix `plotly`
   
   after this fix, do it still works with pandas 1.4.x?


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


[GitHub] [spark] xinrong-meng commented on pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

Posted by GitBox <gi...@apache.org>.
xinrong-meng commented on PR #38033:
URL: https://github.com/apache/spark/pull/38033#issuecomment-1271028888

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


[GitHub] [spark] itholic commented on pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

Posted by GitBox <gi...@apache.org>.
itholic commented on PR #38033:
URL: https://github.com/apache/spark/pull/38033#issuecomment-1263022380

   Yes, the regression is detected only from `matplotlib`.
   
   `plotly` works fine :-)
   
   And yes, it works fine with pandas 1.4.x as CI passes for now.


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


[GitHub] [spark] itholic commented on pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

Posted by GitBox <gi...@apache.org>.
itholic commented on PR #38033:
URL: https://github.com/apache/spark/pull/38033#issuecomment-1262998910

   > I am wondering if we shall rely on `super()._kind` rather than hardcode `_kind`.
   
   Here, the parents for `PandasOnSpark*Plot` are `Pandas*Plot` and `*PlotBase`, so I think it may not possible apply the `super()`?


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


[GitHub] [spark] xinrong-meng commented on pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

Posted by GitBox <gi...@apache.org>.
xinrong-meng commented on PR #38033:
URL: https://github.com/apache/spark/pull/38033#issuecomment-1264042497

   I was thinking something as below, in order to be consistent with pandas and avoid the hardcoding
   ```
   >>> class C:
   ...   @property
   ...   def _kind(self):
   ...     return 'area'
   ... 
   >>> class D:
   ...   pass
   ...
   >>> class PS_C(C, D):  # pandas-on-Spark class
   ...   @property
   ...   def _kind(self):
   ...     return super()._kind
   ... 
   ```
   Then we may change `_plot_klass = {getattr(klass(), "_kind"): klass for klass in _klasses}`


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


[GitHub] [spark] xinrong-meng closed pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

Posted by GitBox <gi...@apache.org>.
xinrong-meng closed pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.
URL: https://github.com/apache/spark/pull/38033


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


[GitHub] [spark] itholic commented on pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

Posted by GitBox <gi...@apache.org>.
itholic commented on PR #38033:
URL: https://github.com/apache/spark/pull/38033#issuecomment-1262996806

   > Shall we follow pandas to make `_kind` a `property`?
   
   We cannot access to the value of  `_kind` without instantiate when it's a property as below:
   
   ```python
   >>> AreaPlot._kind
   <property object at 0x7fe520d749a0>
   ```
   
   It returns the property object, but we want the name of plot in string format as below:
   
   ```python
   >>> AreaPlot._kind
   'area'
   ```
   
   Since we inherit and use the Pandas object, I think that we should explicitly assign the class name to the class member instead of implementing them in the same way.


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


[GitHub] [spark] xinrong-meng commented on pull request #38033: [SPARK-40598][PS] Fix plotting features work properly with pandas 1.5.0.

Posted by GitBox <gi...@apache.org>.
xinrong-meng commented on PR #38033:
URL: https://github.com/apache/spark/pull/38033#issuecomment-1262620060

   I am wondering if we shall rely on `super()._kind` rather than hardcode `_kind`.


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