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

Groupby for hv.Dataset().to.distribution errors #2886

Closed
ahuang11 opened this issue Jul 22, 2018 · 4 comments · Fixed by #4023
Closed

Groupby for hv.Dataset().to.distribution errors #2886

ahuang11 opened this issue Jul 22, 2018 · 4 comments · Fixed by #4023
Assignees
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@ahuang11
Copy link
Collaborator

ahuang11 commented Jul 22, 2018

But works with hvplot

import numpy as np
import hvplot.pandas
import holoviews as hv
hv.extension('bokeh')

from bokeh.sampledata.autompg import autompg as df

title = "MPG by Cylinders and Data Source, Colored by Cylinders"
df.hvplot.kde('mpg', 'cyl')
hv.Dataset(df).to.distribution('mpg', ['cyl'])
~/anaconda3/envs/bokeh-dev/lib/python3.6/site-packages/param/__init__.py in _check_bounds(self, val)
   1171             if min_length is not None and max_length is not None:
   1172                 if not (min_length <= l <= max_length):
-> 1173                     raise ValueError("%s: list length must be between %s and %s (inclusive)"%(self._attrib_name,min_length,max_length))
   1174             elif min_length is not None:
   1175                 if not min_length <= l:

ValueError: kdims: list length must be between 1 and 1 (inclusive)
@marcbernot
Copy link

It is not an error, you need to conform to the syntax of the .to() method.
You operate a groupby on 'cyl' with this line :
df.hvplot.kde('mpg','cyl')
To do the same in holoviews you can use this syntax :
hv.Dataset(df).to(hv.Distribution,'mpg', None,'cyl').overlay()
or
hv.Dataset(df).to(hv.Distribution,kdims='mpg',groupby='cyl').overlay()
Check gridded datasets groupby section to learn more about the .to() method.

@ahuang11
Copy link
Collaborator Author

Ah okay; I guess I'm used to hv.Dataset(df).to.curve('mpg', 'cyl', []) and hv.Dataset(df).to.bars('mpg', 'cyl', []) instead of hv.Dataset(df).to(hv.Curve, 'mpg', 'cyl', []) so I expected hv.Distribution would work similarly. Thanks!

@marcbernot
Copy link

Oh sorry, i think you should reopen this issue and that there is indeed an error.
By looking at the signature of the method you want to use :
.to.distribution(dim=None,groupby=[],**kwargs)
it looks like you should be able to use the syntax:
hv.Dataset(df).to.distribution('mpg', ['cyl'])
or even
hv.Dataset(df).to.distribution('mpg', 'cyl')
At first I thought you could do the groupby only within the .to().

Error 1 : this latter yields a "Dimension 'c' not found" due to the absence of brackets ; but it seems to be an error because holoviews is bracket tolerant in a lot of similar situations.

Error 2 : in element/init.py line 44
hv.Dataset(df).to._element.reindex(['cyl'],['mpg']) yields a :Dataset [cyl] (mpg) so after the groupby you are left with no kdim hence the error "ValueError: kdims: list length must be between 1 and 1 (inclusive)".
reindexed = hv.Dataset(df).to._element.reindex(['cyl','mpg']) reindexed.groupby('cyl',hv.HoloMap,hv.Distribution).overlay()
gives the expected result.

@ahuang11 ahuang11 reopened this Jul 24, 2018
@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Aug 4, 2018
@philippjfr philippjfr added this to the v1.12.6 milestone Oct 3, 2019
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants