-
Notifications
You must be signed in to change notification settings - Fork 358
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
ENH: Implement frame plot #686
Merged
HyukjinKwon
merged 7 commits into
databricks:master
from
charlesdong1991:implement_frame_plot
Aug 26, 2019
+292
−4
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
88f594c
Implement frame plot
charlesdong1991 55671fb
Merge remote-tracking branch 'upstream/master' into implement_frame_plot
charlesdong1991 4c8d5b6
fix linting error
charlesdong1991 834101c
Add doc and test and missing functions
charlesdong1991 c23c428
correct typo
charlesdong1991 5cea031
linting
charlesdong1991 14a55b5
fix lintitn
charlesdong1991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import base64 | ||
from io import BytesIO | ||
|
||
import matplotlib | ||
from matplotlib import pyplot as plt | ||
import pandas as pd | ||
|
||
from databricks import koalas | ||
from databricks.koalas.exceptions import PandasNotImplementedError | ||
from databricks.koalas.testing.utils import ReusedSQLTestCase, TestUtils | ||
|
||
|
||
matplotlib.use('agg') | ||
|
||
|
||
class DataFramePlotTest(ReusedSQLTestCase, TestUtils): | ||
@property | ||
def pdf1(self): | ||
return pd.DataFrame({ | ||
'a': [1, 2, 3, 4, 5, 6, 7, 8, 9, 15, 50], | ||
'b': [2, 3, 4, 5, 7, 9, 10, 15, 34, 45, 49] | ||
}, index=[0, 1, 3, 5, 6, 8, 9, 9, 9, 10, 10]) | ||
|
||
@property | ||
def kdf1(self): | ||
return koalas.from_pandas(self.pdf1) | ||
|
||
@staticmethod | ||
def plot_to_base64(ax): | ||
bytes_data = BytesIO() | ||
ax.figure.savefig(bytes_data, format='png') | ||
bytes_data.seek(0) | ||
b64_data = base64.b64encode(bytes_data.read()) | ||
plt.close(ax.figure) | ||
return b64_data | ||
|
||
def compare_plots(self, ax1, ax2): | ||
self.assert_eq(self.plot_to_base64(ax1), self.plot_to_base64(ax2)) | ||
|
||
def test_line_plot(self): | ||
pdf = self.pdf1 | ||
kdf = self.kdf1 | ||
|
||
ax1 = pdf.plot(kind="line", colormap='Paired') | ||
ax2 = kdf.plot(kind="line", colormap='Paired') | ||
self.compare_plots(ax1, ax2) | ||
|
||
ax3 = pdf.plot.line(colormap='Paired') | ||
ax4 = kdf.plot.line(colormap='Paired') | ||
self.compare_plots(ax3, ax4) | ||
|
||
def test_missing(self): | ||
ks = self.kdf1 | ||
|
||
unsupported_functions = ['area', 'bar', 'barh', 'box', 'density', 'hexbin', | ||
'hist', 'kde', 'pie', 'scatter'] | ||
for name in unsupported_functions: | ||
with self.assertRaisesRegex(PandasNotImplementedError, | ||
"method.*DataFrame.*{}.*not implemented".format(name)): | ||
getattr(ks.plot, name)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we mimic pandas documenation (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.line.html#pandas.DataFrame.plot.line)? It's okay to don't include the images for now.