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 · 7 comments

Comments

Projects
None yet
3 participants
@stsievert
Copy link

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Author

commented Jul 23, 2017

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

This comment has been minimized.

Copy link
Contributor

commented Jul 23, 2017

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

This comment has been minimized.

Copy link
Contributor

commented Jul 23, 2017

@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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Feb 9, 2018

The error message for this case has been improved.

@philippjfr philippjfr closed this Feb 9, 2018

@philippjfr philippjfr modified the milestones: v1.10, 1.9.3 Feb 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.