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

hv.Table(df).to.image throws warning and error #1745

Closed
stsievert opened this issue Jul 22, 2017 · 8 comments
Closed

hv.Table(df).to.image throws warning and error #1745

stsievert opened this issue Jul 22, 2017 · 8 comments
Milestone

Comments

@stsievert
Copy link

stsievert commented Jul 22, 2017

hv.Table(df).to.image(kdims=['samples', 'sparsity'], vdims='error')

throws an warning "WARNING:root:GridImage: GridImage is now deprecated. Please use Image element instead." and an error with a traceback

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-8b2b98813c82> in <module>()
----> 1 data.to.image(kdims=['samples', 'sparsity'], vdims='error')
/Users/scott/anaconda/lib/python3.6/site-packages/holoviews/element/__init__.py in image(self, kdims, vdims, groupby, **kwargs)
---> 58         return self(GridImage, kdims, vdims, groupby, **kwargs)
/Users/scott/anaconda/lib/python3.6/site-packages/holoviews/core/data/__init__.py in __call__(self, new_type, kdims, vdims, groupby, sort, **kwargs)
--> 134                                  group_type=new_type, **params)
/Users/scott/anaconda/lib/python3.6/site-packages/holoviews/core/data/__init__.py in groupby(self, dimensions, container_type, group_type, dynamic, **kwargs)
--> 561                                       group_type, **kwargs)
/Users/scott/anaconda/lib/python3.6/site-packages/holoviews/core/data/pandas.py in groupby(cls, columns, dimensions, container_type, group_type, **kwargs)
--> 128                 columns.data.groupby(group_by, sort=False)]
/Users/scott/anaconda/lib/python3.6/site-packages/holoviews/core/data/pandas.py in <listcomp>(.0)
--> 127         data = [(k, group_type(v, **group_kwargs)) for k, v in
/Users/scott/anaconda/lib/python3.6/site-packages/holoviews/element/raster.py in __init__(self, *args, **kwargs)
--> 443         super(GridImage, self).__init__(*args, **kwargs)
/Users/scott/anaconda/lib/python3.6/site-packages/holoviews/element/raster.py in __init__(self, data, bounds, extents, xdensity, ydensity, **params)
--> 241         dim2, dim1 = self.interface.shape(self, gridded=True)[:2]
TypeError: shape() got an unexpected keyword argument 'gridded'

The below works in the same example above:

hv.Table(df).to.heatmap(kdims=['samples', 'sparsity'], vdims='error')

I'm on holoviews version: 1.8.1.

@jlstevens
Copy link
Contributor

jlstevens commented Jul 23, 2017

Thanks for reporting this!

I think in the first line of code you reported, you meant to write .to.image instead of .to.heatmap.

Anyway, all references to GridImage can be easily be fixed so I'll make a PR to address that. It is possible that this will fix everything here as Image now uses a proper data interface behind the scenes (that hopefully supports the gridded argument properly!).

@stsievert
Copy link
Author

Whoop, I did mean 'to.image'. I've edited to reflect this.

It is possible that this will fix everything

That's what I hoped for.

@jlstevens
Copy link
Contributor

Switching GridImage to Image worked (line 57 of element/__init__.py) but unfortunately the .to.image isn't correctly converting from columnar to gridded formats just yet.

Here is my current workaround to convert from a Table to an Image:

image

I don't see any reason why the .to interface couldn't be updated to handle this for you, though I need to check with @philippjfr to make sure. Lastly, I should just mention that storing raster type data in tabular format is never going to be the most efficient of things! :-)

@jlstevens
Copy link
Contributor

@philippjfr

The way I'm reading the code, it seems that the call to the Dataset constructor is resulting in a non-gridded interface being set, leaving the .data in a format that doesn't work with Image. I'm thinking we just need a method on interface to convert to/from gridded formats appropriately. Is that right? Or is this supposed to be working and there is some other bug causing the issue?

@philippjfr
Copy link
Member

philippjfr commented Jul 30, 2017

The way I'm reading the code, it seems that the call to the Dataset constructor is resulting in a non-gridded interface being set, leaving the .data in a format that doesn't work with Image. I'm thinking we just need a method on interface to convert to/from gridded formats appropriately.

It's not clear to me what converting to/from gridded formats means for a Table. We have two ways of converting tabular data to an image-like thing, the first is categorical_aggregate2D which assumes that the x- and y-values are categorical and is used by HeatMap to get a 2D array for plotting, the second is the datashader aggregate operation which applies 2D binning. Without applying one of these operations it's not clear to me what converting would mean. My preference is to check whether the data is tabular or gridded and throw an exception pointing to these operations if it is tabular.

@jlstevens
Copy link
Contributor

jlstevens commented Jul 30, 2017

@philippjfr Didn't conversions like this work some time in the past? I know a lot has changed as data interfaces have been implemented.

Out of those two options, I was assuming a datashader aggregate style conversion to Image as I would assume the other style would be implicitly chosen by converting to HeatMap instead.

My preference is to check whether the data is tabular or gridded and throw an exception pointing to these operations if it is tabular.

That would be fine by me if we are convinced there is no sensible automatic policy.

Edit: @philippjfr I realize I might be remembering conversion from Images to Tables, not the other way around...

@philippjfr
Copy link
Member

The error message for this case has been improved.

@philippjfr philippjfr modified the milestones: v1.10, 1.9.3 Feb 10, 2018
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
None yet
Projects
None yet
Development

No branches or pull requests

3 participants