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

Shape.from_record crashes when a dataset is supplied #1248

Closed
Guillemdb opened this issue Apr 7, 2017 · 18 comments
Closed

Shape.from_record crashes when a dataset is supplied #1248

Guillemdb opened this issue Apr 7, 2017 · 18 comments

Comments

@Guillemdb
Copy link

Guillemdb commented Apr 7, 2017

I have found some bugs when trying to use the Shape.from_record function both in bokeh and matplotlib backends.

Here is some information about what is failing and how to reproduce the bug:

Package versions:

Last versions from the holoviews and the geoviews cloned repos.
Jupyter:
jupyter==1.0.0
jupyter-client==5.0.1
jupyter-console==5.1.0
jupyter-core==4.3.0

Bokeh: bokeh==0.12.5

Bug description:

I was trying to replicate the kind of plots used to show the results of the brexit referendum described here: https://www.continuum.io/blog/developer-blog/introducing-geoviews

map_plot

Matplotlib backend
Works well if no dataset is used to color the plot.

If I create the plot with a supplied dataset I get an error (stacktrace at the bottom)

With the following workaround in the _norm_kwargs function in the /plotting/mpl/element.py file I get the colors to work:

      try:
          if values.dtype.kind not in 'OSUM':
            el_min, el_max = np.nanmin(values), np.nanmax(values)
          else:
            el_min, el_max = -np.inf, np.inf
      except:
          print("error in hv/plotting/mpl/element _norm_kwargs")
          el_min, el_max = np.nanmin(values), np.nanmax(values)

This error is raised due to values being a list and not having the dtype attribute. I didn't go through all your code, but if this is intended to check if all the values are nan/inf maybe using np.isnan or np.isinf would be a good idea.

mpl_colors

It works when ignoring the dtype check as long as there is a valid value to plot.
workaround

bokeh backend

In this case, with a similar workaround I am able to display the bokeh plot with tooltip information, but I am unable to apply a color mapping to the different patches:
bokeh_backend

In this case the error is located in the /plotting/bokeh/util.py file in the filter_batched_data function.

The workaround I used:

try:
          if len(np.unique(values)) == 1:
            mapping[k] = values[0]
            del data[v]
except:
          print("error in hv/plotting/bokeh/util filter_batched_data")
``

It fails in the np.unique(values) execution. I am not able to figure out why.

## Stacktraces

- **matplotlib**


AttributeError Traceback (most recent call last)
/home/kalidus/anaconda3/lib/python3.5/site-packages/IPython/core/formatters.py in call(self, obj)
305 pass
306 else:
--> 307 return printer(obj)
308 # Finally look for special method names
309 method = get_real_method(obj, self.print_method)

/home/kalidus/github/holoviews/holoviews/ipython/display_hooks.py in pprint_display(obj)
236 if not ip.display_formatter.formatters['text/plain'].pprint:
237 return None
--> 238 return display(obj, raw=True)
239
240

/home/kalidus/github/holoviews/holoviews/ipython/display_hooks.py in display(obj, raw, **kwargs)
218 html = grid_display(obj)
219 elif isinstance(obj, (CompositeOverlay, ViewableElement)):
--> 220 html = element_display(obj)
221 elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
222 html = layout_display(obj)

/home/kalidus/github/holoviews/holoviews/ipython/display_hooks.py in wrapped(element)
147 if sys.version_info[0] < 3:
148 raise (t, v, tb)
--> 149 raise v.with_traceback(tb)
150 return wrapped
151

/home/kalidus/github/holoviews/holoviews/ipython/display_hooks.py in wrapped(element)
114 html = fn(element,
115 max_frames=OutputMagic.options['max_frames'],
--> 116 max_branches = OutputMagic.options['max_branches'])
117
118 # Only want to add to the archive for one display hook...

/home/kalidus/github/holoviews/holoviews/ipython/display_hooks.py in element_display(element, max_frames, max_branches)
164 if renderer.fig == 'pdf':
165 renderer = renderer.instance(fig='png')
--> 166 return renderer.html(element, fmt=renderer.fig)
167
168

/home/kalidus/github/holoviews/holoviews/plotting/renderer.py in html(self, obj, fmt, css, comm, **kwargs)
251 code to initialize a Comm, if the plot supplies one.
252 """
--> 253 plot, fmt = self._validate(obj, fmt)
254 figdata, _ = self(plot, fmt, **kwargs)
255 if css is None: css = self.css

/home/kalidus/github/holoviews/holoviews/plotting/renderer.py in _validate(self, obj, fmt)
187 if isinstance(obj, tuple(self.widgets.values())):
188 return obj, 'html'
--> 189 plot = self.get_plot(obj, renderer=self)
190
191 fig_formats = self.mode_formats['fig'][self.mode]

/home/kalidus/github/holoviews/holoviews/plotting/renderer.py in get_plot(self_or_cls, obj, renderer)
174 plot = self_or_cls.plotting_class(obj)(obj, renderer=renderer,
175 **plot_opts)
--> 176 plot.update(0)
177 else:
178 plot = obj

/home/kalidus/github/holoviews/holoviews/plotting/mpl/plot.py in update(self, key)
222 def update(self, key):
223 if len(self) == 1 and key == 0 and not self.drawn:
--> 224 return self.initialize_plot()
225 return self.getitem(key)
226

/home/kalidus/github/holoviews/holoviews/plotting/mpl/plot.py in wrapper(self, *args, **kwargs)
26 def wrapper(self, *args, **kwargs):
27 with mpl.rc_context(rc=self.fig_rcparams):
---> 28 return f(self, *args, **kwargs)
29 return wrapper
30

/home/kalidus/github/holoviews/holoviews/plotting/mpl/element.py in initialize_plot(self, ranges)
827 ranges = self.compute_ranges(self.hmap, key, ranges)
828 for k, subplot in self.subplots.items():
--> 829 subplot.initialize_plot(ranges=ranges)
830 if isinstance(element, CompositeOverlay):
831 frame = element.get(k, None)

/home/kalidus/github/holoviews/holoviews/plotting/mpl/plot.py in wrapper(self, *args, **kwargs)
26 def wrapper(self, *args, **kwargs):
27 with mpl.rc_context(rc=self.fig_rcparams):
---> 28 return f(self, *args, **kwargs)
29 return wrapper
30

/home/kalidus/github/holoviews/holoviews/plotting/mpl/element.py in initialize_plot(self, ranges)
481 style['label'] = element.label
482
--> 483 plot_data, plot_kwargs, axis_kwargs = self.get_data(element, ranges, style)
484
485 with abbreviated_exception():

/home/kalidus/github/geoviews/geoviews/plotting/mpl/init.py in get_data(self, element, ranges, style)
307 value = element.level
308 if vdim is not None and (value is not None and np.isfinite(value)):
--> 309 self._norm_kwargs(element, ranges, style, vdim)
310 style['clim'] = style.pop('vmin'), style.pop('vmax')
311 style['array'] = np.array([value]*len(element.data))

/home/kalidus/github/holoviews/holoviews/plotting/mpl/element.py in _norm_kwargs(self, element, ranges, opts, vdim)
668 #print(values,element)
669
--> 670 if values.dtype.kind not in 'OSUM':
671 el_min, el_max = np.nanmin(values), np.nanmax(values)
672 else:

AttributeError: 'list' object has no attribute 'dtype'


- **bokeh**


ValueError Traceback (most recent call last)
/home/kalidus/anaconda3/lib/python3.5/site-packages/IPython/core/formatters.py in call(self, obj)
305 pass
306 else:
--> 307 return printer(obj)
308 # Finally look for special method names
309 method = get_real_method(obj, self.print_method)

/home/kalidus/github/holoviews/holoviews/ipython/display_hooks.py in pprint_display(obj)
236 if not ip.display_formatter.formatters['text/plain'].pprint:
237 return None
--> 238 return display(obj, raw=True)
239
240

/home/kalidus/github/holoviews/holoviews/ipython/display_hooks.py in display(obj, raw, **kwargs)
218 html = grid_display(obj)
219 elif isinstance(obj, (CompositeOverlay, ViewableElement)):
--> 220 html = element_display(obj)
221 elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
222 html = layout_display(obj)

/home/kalidus/github/holoviews/holoviews/ipython/display_hooks.py in wrapped(element)
147 if sys.version_info[0] < 3:
148 raise (t, v, tb)
--> 149 raise v.with_traceback(tb)
150 return wrapped
151

/home/kalidus/github/holoviews/holoviews/ipython/display_hooks.py in wrapped(element)
114 html = fn(element,
115 max_frames=OutputMagic.options['max_frames'],
--> 116 max_branches = OutputMagic.options['max_branches'])
117
118 # Only want to add to the archive for one display hook...

/home/kalidus/github/holoviews/holoviews/ipython/display_hooks.py in element_display(element, max_frames, max_branches)
164 if renderer.fig == 'pdf':
165 renderer = renderer.instance(fig='png')
--> 166 return renderer.html(element, fmt=renderer.fig)
167
168

/home/kalidus/github/holoviews/holoviews/plotting/renderer.py in html(self, obj, fmt, css, comm, **kwargs)
251 code to initialize a Comm, if the plot supplies one.
252 """
--> 253 plot, fmt = self._validate(obj, fmt)
254 figdata, _ = self(plot, fmt, **kwargs)
255 if css is None: css = self.css

/home/kalidus/github/holoviews/holoviews/plotting/renderer.py in _validate(self, obj, fmt)
187 if isinstance(obj, tuple(self.widgets.values())):
188 return obj, 'html'
--> 189 plot = self.get_plot(obj, renderer=self)
190
191 fig_formats = self.mode_formats['fig'][self.mode]

/home/kalidus/github/holoviews/holoviews/plotting/renderer.py in get_plot(self_or_cls, obj, renderer)
174 plot = self_or_cls.plotting_class(obj)(obj, renderer=renderer,
175 **plot_opts)
--> 176 plot.update(0)
177 else:
178 plot = obj

/home/kalidus/github/holoviews/holoviews/plotting/plot.py in update(self, key)
478 def update(self, key):
479 if len(self) == 1 and key == 0 and not self.drawn:
--> 480 return self.initialize_plot()
481 return self.getitem(key)
482

/home/kalidus/github/holoviews/holoviews/plotting/bokeh/element.py in initialize_plot(self, ranges, plot, plots)
1215 frame = None
1216 if self.tabs: subplot.overlaid = False
-> 1217 child = subplot.initialize_plot(ranges, plot, plots)
1218 if isinstance(element, CompositeOverlay):
1219 frame = element.get(key, None)

/home/kalidus/github/holoviews/holoviews/plotting/bokeh/element.py in initialize_plot(self, ranges, plot, plots, source)
696 empty = False
697 if self.batched:
--> 698 data, mapping = self.get_batched_data(element, ranges, empty)
699 else:
700 data, mapping = self.get_data(element, ranges, empty)

/home/kalidus/github/holoviews/holoviews/plotting/bokeh/path.py in get_batched_data(self, element, ranges, empty)
58 data[k].extend(list(v))
59
---> 60 filter_batched_data(data, elmapping)
61 return data, elmapping
62

/home/kalidus/github/holoviews/holoviews/plotting/bokeh/util.py in filter_batched_data(data, mapping)
605 values = data[v]
606
--> 607 if len(np.unique(values)) == 1:
608 mapping[k] = values[0]
609 del data[v]

/home/kalidus/anaconda3/lib/python3.5/site-packages/numpy/lib/arraysetops.py in unique(ar, return_index, return_inverse, return_counts)
212 aux = ar[perm]
213 else:
--> 214 ar.sort()
215 aux = ar
216 flag = np.concatenate(([True], aux[1:] != aux[:-1]))

ValueError: operands could not be broadcast together with shapes (9,) (61,)





@philippjfr
Copy link
Member

Thanks for the detailed bug report! This was likely introduced in #1241. I'll investigate today.

@philippjfr
Copy link
Member

@Guillem-db Introduced a PR with a number of small fixes, which should address everything mentioned here. Would be very helpful if you could test it before or after it is merged.

@Guillemdb
Copy link
Author

@philippjfr I am on it!

@Guillemdb
Copy link
Author

@philippjfr now it works like a charm. Thank you very much, you are doing a great job!
like a charm

@Guillemdb
Copy link
Author

I found a really weird bug. Not sure if it's a bokeh bug or holoviews/geoviews related.
When using a dataset with columns that contains spacing or any symbol besides '_' the colors in the plot are not displayed correctly.

spacing
underscore
other signs

@philippjfr
Copy link
Member

Very odd, looking into it.

@Guillemdb
Copy link
Author

This makes the color fail but the tooltips are displayed correctly.

If you try to use accents then you can correctly see the displayed colors but then the tooltip fails.

accents

@philippjfr
Copy link
Member

Wonder if some of these are bokeh level issues, with the original dataset adding spaces I can't reproduce the blank colors but the colormapping is still completely wrong. I'll try to work it out.

@philippjfr
Copy link
Member

@Guillem-db Now pushed fixes for the colormapping to both HoloViews and GeoViews. Would be great if you could test again.

@Guillemdb
Copy link
Author

I tested the new commits. It displays correctly the columns with accents, but still fails displaying tooltips with accents and colors with spaces/punctuation signs. I will try to reproduce the problem using only bokeh to see if it only happens when using holowievs.

still failing

@Guillemdb
Copy link
Author

The tooltip bug is also found in bokeh. I dont know how to quickly reproduce the color bug using only bokeh. If I come up with any idea I will try.

bokeh fails too

@philippjfr
Copy link
Member

I tested the new commits. It displays correctly the columns with accents, but still fails displaying tooltips with accents and colors with spaces/punctuation signs. I will try to reproduce the problem using only bokeh to see if it only happens when using holowievs.

Did you also pull GeoViews master?

The tooltip bug is also found in bokeh. I dont know how to quickly reproduce the color bug using only bokeh. If I come up with any idea I will try.

That's good to know, I'll try to reproduce in bokeh and will file an issue.

@Guillemdb
Copy link
Author

Did you also pull GeoViews master?

Nope, my bad :P
Now that I did it works well. Consider it fixed!

my bad

@philippjfr
Copy link
Member

@Guillem-db My latest PR (#1250) fixes the hover issue is well, I just had to escape the column specification on the hover tool with some curly brackets.

@jbednar
Copy link
Member

jbednar commented Apr 7, 2017

Is this something Bokeh should be doing, or is it already ok because Bokeh expects its users (us in this case) to do the escaping?

@philippjfr
Copy link
Member

is it already ok because Bokeh expects its users (us in this case) to do the escaping?

Right, it's actually a frequent issue I see popping up on bokeh mailing lists and issues. Just assumed I'd already done that.

@philippjfr
Copy link
Member

Anyway, all issues mentioned in this PR have been fixed as far as I'm aware. Please reopen if you run into any further problems.

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 25, 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