Skip to content

Commit 536ea18

Browse files
charlesdong1991HyukjinKwon
authored andcommitted
BUG&TST: Fix area plot for Series and add test (#704)
There seems a little bug in SamplePlot that failed area plot. It is due to after sampling, since `scol` is not assigned, it will return a full DataFrame instead of Series. And looks like area plot turns good as well after fixing it. ![Screen Shot 2019-08-27 at 10 21 03 PM](https://user-images.githubusercontent.com/9269816/63805466-c94ad200-c919-11e9-8838-94d4a1587ebb.png) Before the bug fixing, the area plot looks like: ![Screen Shot 2019-08-27 at 10 40 23 PM](https://user-images.githubusercontent.com/9269816/63806354-b802c500-c91b-11e9-8fc3-6131f9c5ba3f.png)
1 parent a449894 commit 536ea18

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

databricks/koalas/plot.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ def get_sampled(self, data):
9090
sampled = data._sdf.sample(fraction=float(self.fraction))
9191
return DataFrame(data._internal.copy(sdf=sampled)).to_pandas()
9292
elif isinstance(data, Series):
93+
scol = data._kdf._internal.data_scols[0]
9394
sampled = data._kdf._sdf.sample(fraction=float(self.fraction))
94-
return DataFrame(data._kdf._internal.copy(sdf=sampled)).to_pandas()
95+
return DataFrame(data._kdf._internal.copy(sdf=sampled, scol=scol)).to_pandas()
9596
else:
9697
ValueError("Only DataFrame and Series are supported for plotting.")
9798

databricks/koalas/tests/test_series_plot.py

+21
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,27 @@ def test_hist_summary(self):
179179
self.assert_eq(pd.Series(expected_bins), pd.Series(bins))
180180
self.assert_eq(pd.Series(expected_histogram), histogram)
181181

182+
def test_area_plot(self):
183+
pdf = pd.DataFrame({
184+
'sales': [3, 2, 3, 9, 10, 6],
185+
'signups': [5, 5, 6, 12, 14, 13],
186+
'visits': [20, 42, 28, 62, 81, 50],
187+
}, index=pd.date_range(start='2018/01/01', end='2018/07/01', freq='M'))
188+
kdf = koalas.from_pandas(pdf)
189+
190+
ax1 = pdf['sales'].plot("area", colormap='Paired')
191+
ax2 = kdf['sales'].plot("area", colormap='Paired')
192+
self.compare_plots(ax1, ax2)
193+
194+
ax1 = pdf['sales'].plot.area(colormap='Paired')
195+
ax2 = kdf['sales'].plot.area(colormap='Paired')
196+
self.compare_plots(ax1, ax2)
197+
198+
# just a sanity check for df.col type
199+
ax1 = pdf.sales.plot("area", colormap='Paired')
200+
ax2 = kdf.sales.plot("area", colormap='Paired')
201+
self.compare_plots(ax1, ax2)
202+
182203
def boxplot_comparison(self, *args, **kwargs):
183204
pdf = self.pdf1
184205
kdf = self.kdf1

0 commit comments

Comments
 (0)