Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some examples for plot implementations in their docstrings #847

Merged
merged 13 commits into from
Oct 2, 2019

Conversation

itholic
Copy link
Contributor

@itholic itholic commented Sep 30, 2019

Basically we finished the rough implementation of all plots (except 2 in DataFrame).

So it should be better to have some examples for them.

@codecov-io
Copy link

codecov-io commented Sep 30, 2019

Codecov Report

Merging #847 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #847      +/-   ##
==========================================
+ Coverage   94.27%   94.28%   +<.01%     
==========================================
  Files          34       34              
  Lines        6150     6154       +4     
==========================================
+ Hits         5798     5802       +4     
  Misses        352      352
Impacted Files Coverage Δ
databricks/koalas/plot.py 94.28% <ø> (ø) ⬆️
databricks/conftest.py 97.87% <100%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1003df7...eaa981e. Read the comment docs.

:context: close-figs

>>> s = ks.Series([1, 3, 2])
>>> ax = s.plot.line() # doctest: +SKIP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we skip?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HyukjinKwon This doctest continuously failed on my local test bed like below:

스크린샷 2019-09-30 오후 4 40 07

But it actually works well without exception:

스크린샷 2019-09-30 오후 4 39 37

so i wanna discussion with others members.

could you test this on your local if when available or have some insight of above failure?

Copy link
Contributor Author

@itholic itholic Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just undo this skip and pushed again for travis build check. (maybe it will pass on travis server..?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed again. 😢 Do you have any guesswork ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well i just try this doctest again with exactly same test in test_series_plot. But still failed.

스크린샷 2019-09-30 오후 5 57 49

above passed, but below not.

스크린샷 2019-09-30 오후 5 58 45

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, it works! Thanks ! 😸

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close-figs doesn't seem to close figures.

995 
996         Examples
997         --------
998         Basic plot.
999 
1000         .. plot::
1001             :context: close-figs
1002 
1003             >>> import matplotlib.pyplot as plt
1004             >>> plt.get_fignums()
Expected nothing
Got:
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]

/Users/harutaka/Desktop/projects/koalas/databricks/koalas/plot.py:1004: DocTestFailure

Copy link
Contributor Author

@itholic itholic Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charlesdong1991 yeah i totally agree with it. I think i should be find better solution for solve this issue to keep consistency & readable of docs.
@harupy you're right. i think maybe close-figs doesn't work properly either. im going to figure out why this happened 😭

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does close-figs has any effect when running tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harupy Oops.. sorry i missed your reply
Anyway, yes it seems have any effect, because they are showing same result when i remove all close-figs options.

@HyukjinKwon
Copy link
Member

This is nice. Thanks for working on this @itholic

@itholic
Copy link
Contributor Author

itholic commented Sep 30, 2019

@HyukjinKwon my pleasure.

databricks/koalas/plot.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@ueshin ueshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add for Series.plot.barh and Series.plot.pie?

:context: close-figs

>>> import matplotlib.pyplot as plt
>>> plt.close('all')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this?
Seems like others don't have this, otherwise we need to add for the others?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ueshin at above discussions, maybe there is an issue that :context: close-figs doesn't work properly. so now it wouldn't work if we remove the line plt.close('all') to explicitly close all plots. i'm going to figure out how can we solve this problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itholic
I think :context: close-figs is just for Sphinx, and does nothing when pytest runs tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when running tests, all the plots are drawn onto the same ax and get messed up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harupy Thanks for comment!! It really makes sense. Then i think maybe we need to skip these all examples on pytest, and added them separate unittest (actually most of them already tested in unittest suite though)

Copy link
Contributor

@harupy harupy Oct 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I'm not sure if this is right because plt.close("all") is also called on tests which are not related to plots.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah? sorry i can't get it perfectly 😢 maybe could you let me know where they are using for tests not related to plots?

Copy link
Contributor

@harupy harupy Oct 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plt.close is called on test functions where we don't need to call plt.close.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it :)
but maybe i think they are only called when we explicitly write the :context: close-figs in doctest, ain't they?

Copy link
Contributor

@harupy harupy Oct 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no

@ueshin
Copy link
Collaborator

ueshin commented Sep 30, 2019

Btw, seems like dev/lint-python will fail after docs are built since some python files are generated in ./docs/build/html/reference/api.

starting pycodestyle test...
pycodestyle checks failed:
./docs/build/html/reference/api/databricks-koalas-frame-DataFrame-plot-bar-1.py:1:25: E231 missing whitespace after ':'
./docs/build/html/reference/api/databricks-koalas-frame-DataFrame-plot-bar-1.py:1:48: E231 missing whitespace after ':'
./docs/build/html/reference/api/databricks-koalas-frame-DataFrame-plot-hist-1.py:3:12: E251 unexpected spaces around keyword / parameter equals
./docs/build/html/reference/api/databricks-koalas-frame-DataFrame-plot-hist-1.py:3:14: E251 unexpected spaces around keyword / parameter equals
./docs/build/html/reference/api/databricks-koalas-frame-DataFrame-plot-pie-1.py:1:40: E203 whitespace before ','
./docs/build/html/reference/api/databricks-koalas-frame-DataFrame-plot-line-1.py:5:4: E121 continuation line under-indented for hanging indent
./docs/build/html/reference/api/databricks-koalas-frame-DataFrame-plot-line-1.py:7:4: E123 closing bracket does not match indentation of opening bracket's line
./docs/build/html/reference/api/databricks-koalas-frame-DataFrame-plot-barh-1.py:1:25: E231 missing whitespace after ':'
./docs/build/html/reference/api/databricks-koalas-frame-DataFrame-plot-barh-1.py:1:48: E231 missing whitespace after ':'

Can we ignore those files when running pycodestyle?

@itholic
Copy link
Contributor Author

itholic commented Oct 1, 2019

@ueshin Thanks for comment!
I think maybe we already have examples for Series.plot.barh and Series.plot.pie , but maybe is there a problem with that examples or wanna make additional ones? 😃

@itholic
Copy link
Contributor Author

itholic commented Oct 1, 2019

@ueshin And I'm going to make them ignore in pycodestyle! Thanks for review :)

@ueshin
Copy link
Collaborator

ueshin commented Oct 1, 2019

@itholic I mean, when I generated the doc, I couldn't see the plots for Series.plot.barh and Series.plot.pie. I thought we need

        .. plot::
            :context: close-figs

tags for them as well, then we can see the plots?

@itholic
Copy link
Contributor Author

itholic commented Oct 1, 2019

@ueshin oh i got it :) yes we can see the plots in generated docs by adding .. plot::

i'm going to add them to Series.plot.barh & Series.plot.pie either for visualize plots in docs 😄

.. plot::
:context: close-figs

>>> df = ks.DataFrame({'mass': [0.330, 4.87, 5.97],
... 'radius': [2439.7, 6051.8, 6378.1]},
... index=['Mercury', 'Venus', 'Earth'])
>>> plot = df.mass.plot.pie(figsize=(5, 5))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indent should be one more level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for comment!! fixed it :)

@pytest.fixture(autouse=True)
def close_figs():
yield
plt.close("all")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this to conftest.py?

Copy link
Contributor Author

@itholic itholic Oct 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again, i moved this to conftest.py :)

Copy link
Collaborator

@ueshin ueshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending tests.

@ueshin
Copy link
Collaborator

ueshin commented Oct 1, 2019

oh, I forgot about #847 (comment).
Seems like pycodestyle still fails after creating docs.

starting pycodestyle test...
pycodestyle checks failed:
./docs/build/html/reference/api/databricks-koalas-series-Series-plot-line-1.py:1:17: E203 whitespace before ','
./docs/build/html/reference/api/databricks-koalas-series-Series-plot-line-1.py:1:18: E231 missing whitespace after ','
./docs/build/html/reference/api/databricks-koalas-series-Series-plot-line-1.py:1:20: E203 whitespace before ','
./docs/build/html/reference/api/databricks-koalas-series-Series-plot-line-1.py:1:21: E231 missing whitespace after ','

@itholic
Copy link
Contributor Author

itholic commented Oct 2, 2019

@ueshin oops, sorry i'm going to fix them soon

@itholic
Copy link
Contributor Author

itholic commented Oct 2, 2019

@ueshin Suddenly, i have some question. Is it right way we ignore these tests rather than fix lint fails on doctest in created docs? maybe is it better let them as is to keep lint consistency in documentation?

@softagram-bot
Copy link

Softagram Impact Report for pull/847 (head commit: eaa981e)

⭐ Change Overview

Showing the changed files, dependency changes and the impact - click for full size
(Open in Softagram Desktop for full details)

📄 Full report

Impact Report explained. Give feedback on this report to [email protected]

@ueshin
Copy link
Collaborator

ueshin commented Oct 2, 2019

We should definitely keep lint consistency even in documentations.
But the problem here is the generated .py files under the ./docs/build won't follow the rule.
Could you try dev/lint-python after generating docs and see what happens?
Now flake8 shows a lot of errors.
But maybe we should fix them in a separate PR. WDYT? @HyukjinKwon

@itholic
Copy link
Contributor Author

itholic commented Oct 2, 2019

@ueshin ah, i just tried, understood why we should ignore them. thanks for explanation! 👍

Copy link
Collaborator

@ueshin ueshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd merge this for now.

@itholic Please submit another PR to fix lint-python for the generated codes, and address the comment below if needed.

databricks/koalas/plot.py Show resolved Hide resolved
@ueshin ueshin merged commit 89877ce into databricks:master Oct 2, 2019
@ueshin
Copy link
Collaborator

ueshin commented Oct 2, 2019

Hmm, our official doc doesn't show all the plots. https://koalas.readthedocs.io/en/latest/reference/series.html#plotting
It shows bar, barh, or pie, but doesn't the others.
We might miss something for Read the Docs service.

@ueshin
Copy link
Collaborator

ueshin commented Oct 3, 2019

Unsupported class file major version 55

@HyukjinKwon
Copy link
Member

@itholic can you take a look and make a fix?

@itholic
Copy link
Contributor Author

itholic commented Oct 3, 2019

@ueshin @HyukjinKwon , okay i'm going to take a look at it and summit another PR for fix them.

ueshin pushed a commit that referenced this pull request Oct 3, 2019
Related with #847 (review) ,

Fixed flake8 to ignore "docs/build/html/reference/api/*.py"

in my local test, it works well, and all plots visible in documentation like below:

<img width="927" alt="스크린샷 2019-10-03 오후 2 19 36" src="https://user-images.githubusercontent.com/44108233/66101387-a0d58800-e5e9-11e9-813d-fc48ce117327.png">
@itholic itholic deleted the add_examples_plot branch October 3, 2019 07:36
rising-star92 added a commit to rising-star92/databricks-koalas that referenced this pull request Jan 27, 2023
Related with databricks/koalas#847 (review) ,

Fixed flake8 to ignore "docs/build/html/reference/api/*.py"

in my local test, it works well, and all plots visible in documentation like below:

<img width="927" alt="스크린샷 2019-10-03 오후 2 19 36" src="https://user-images.githubusercontent.com/44108233/66101387-a0d58800-e5e9-11e9-813d-fc48ce117327.png">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants