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

Optimize handling of wide datasets and Pandas indexes #1350

Merged
merged 15 commits into from
Jul 23, 2024
Merged
5 changes: 3 additions & 2 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2123,8 +2123,9 @@ def chart(self, element, x, y, data=None):

charts = []
for c in y:
kdims, vdims = self._get_dimensions([x], [c])
chart = element(data, kdims, vdims).redim(**{c: self.value_label})
ydim = hv.Dimension(c, label=self.value_label)
kdims, vdims = self._get_dimensions([x], [ydim])
chart = element(data, kdims, vdims)
charts.append((c, chart.relabel(**self._relabel).redim(**self._redim)))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's also skip relabel and redim if self._relabel and self._redim are empty respectively.

return (
self._by_type(charts, self.group_label, sort=False)
Expand Down
21 changes: 11 additions & 10 deletions hvplot/tests/testcharts.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ def test_wide_chart(self, kind, element):
plot = self.df.hvplot(kind=kind)
obj = NdOverlay(
{
'x': element(self.df, 'index', 'x').redim(x='value'),
'y': element(self.df, 'index', 'y').redim(y='value'),
'x': element(self.df, 'index', Dimension('x', label='value')),
'y': element(self.df, 'index', Dimension('y', label='value')),
},
'Variable',
)
Expand All @@ -177,8 +177,8 @@ def test_wide_chart_labels(self, kind, element):
plot = self.df.hvplot(kind=kind, value_label='Test', group_label='Category')
obj = NdOverlay(
{
'x': element(self.df, 'index', 'x').redim(x='Test'),
'y': element(self.df, 'index', 'y').redim(y='Test'),
'x': element(self.df, 'index', Dimension('x', label='Test')),
'y': element(self.df, 'index', Dimension('y', label='Test')),
},
'Category',
)
Expand Down Expand Up @@ -270,8 +270,8 @@ def test_area_stacked(self):
plot = self.df.hvplot.area(stacked=True)
obj = NdOverlay(
{
'x': Area(self.df, 'index', 'x').redim(x='value'),
'y': Area(self.df, 'index', 'y').redim(y='value'),
'x': Area(self.df, 'index', Dimension('x', label='value')),
'y': Area(self.df, 'index', Dimension('y', label='value')),
},
'Variable',
)
Expand Down Expand Up @@ -323,8 +323,8 @@ def test_only_includes_num_chart(self, kind, element):
plot = self.cat_df.hvplot(kind=kind)
obj = NdOverlay(
{
'x': element(self.cat_df, 'index', 'x').redim(x='value'),
'y': element(self.cat_df, 'index', 'y').redim(y='value'),
'x': element(self.cat_df, 'index', Dimension('x', label='value')),
'y': element(self.cat_df, 'index', Dimension('y', label='value')),
},
'Variable',
)
Expand All @@ -335,10 +335,11 @@ def test_includes_str_if_no_num_chart(self, kind, element):
plot = self.cat_only_df.hvplot(kind=kind)
obj = NdOverlay(
{
'upper': element(self.cat_only_df, 'index', 'upper').redim(upper='value'),
'lower': element(self.cat_only_df, 'index', 'lower').redim(lower='value'),
'upper': element(self.cat_only_df, 'index', Dimension('upper', label='value')),
'lower': element(self.cat_only_df, 'index', Dimension('lower', label='value')),
},
'Variable',
sort=False,
)
self.assertEqual(plot, obj)

Expand Down
Loading