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

Fetching Points from geopandas dataframes seems not to work #105

Closed
krvkir opened this issue Nov 28, 2017 · 1 comment
Closed

Fetching Points from geopandas dataframes seems not to work #105

krvkir opened this issue Nov 28, 2017 · 1 comment

Comments

@krvkir
Copy link

krvkir commented Nov 28, 2017

I have a geodataframe with shapely.geometry.Point objects. I try to make geoviews.Points from it with the following code:

from shapely.geometry import Point

gdf = gpd.GeoDataFrame({
    'geometry': [Point([52., 37.]), Point([52., 38.]), Point([52., 38.])],
    'value': [1, 2, 3],
})

gv.Points(gdf)

This results in the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: '<' not supported between instances of 'Point' and 'Point'

The above exception was the direct cause of the following exception:

SystemError                               Traceback (most recent call last)
SystemError: <method-wrapper '__gt__' of Point object at 0x0000019DD6D34438> returned a result with an error set

The above exception was the direct cause of the following exception:

SystemError                               Traceback (most recent call last)
SystemError: <method-wrapper '__lt__' of Point object at 0x0000019DD6D34D68> returned a result with an error set

The above exception was the direct cause of the following exception:

SystemError                               Traceback (most recent call last)
C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\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)

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in pprint_display(obj)
    257     if not ip.display_formatter.formatters['text/plain'].pprint:
    258         return None
--> 259     return display(obj, raw=True)
    260 
    261 

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in display(obj, raw, **kwargs)
    237     elif isinstance(obj, (CompositeOverlay, ViewableElement)):
    238         with option_state(obj):
--> 239             html = element_display(obj)
    240     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
    241         with option_state(obj):

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in wrapped(element)
    130         try:
    131             html = fn(element,
--> 132                       max_frames=OutputSettings.options['max_frames'])
    133 
    134             # Only want to add to the archive for one display hook...

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in element_display(element, max_frames)
    176     if renderer.fig == 'pdf':
    177         renderer = renderer.instance(fig='png')
--> 178     return renderer.html(element, fmt=renderer.fig)
    179 
    180 

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\plotting\renderer.py in html(self, obj, fmt, css, comm, **kwargs)
    255         code to initialize a Comm, if the plot supplies one.
    256         """
--> 257         plot, fmt =  self._validate(obj, fmt)
    258         figdata, _ = self(plot, fmt, **kwargs)
    259         if css is None: css = self.css

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\plotting\renderer.py in _validate(self, obj, fmt)
    191         if isinstance(obj, tuple(self.widgets.values())):
    192             return obj, 'html'
--> 193         plot = self.get_plot(obj, renderer=self)
    194 
    195         fig_formats = self.mode_formats['fig'][self.mode]

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\plotting\bokeh\renderer.py in get_plot(self_or_cls, obj, doc, renderer)
    114         combining the bokeh model with another plot.
    115         """
--> 116         plot = super(BokehRenderer, self_or_cls).get_plot(obj, renderer)
    117         if self_or_cls.mode == 'server' and doc is None:
    118             doc = curdoc()

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\plotting\renderer.py in get_plot(self_or_cls, obj, renderer)
    178             plot = self_or_cls.plotting_class(obj)(obj, renderer=renderer,
    179                                                    **plot_opts)
--> 180             plot.update(0)
    181         else:
    182             plot = obj

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\plotting\plot.py in update(self, key)
    483     def update(self, key):
    484         if len(self) == 1 and key == 0 and not self.drawn:
--> 485             return self.initialize_plot()
    486         item = self.__getitem__(key)
    487         self.traverse(lambda x: setattr(x, '_updated', True))

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\plotting\bokeh\element.py in initialize_plot(self, ranges, plot, plots, source)
    774             element = self.hmap.last
    775         key = self.keys[-1]
--> 776         ranges = self.compute_ranges(self.hmap, key, ranges)
    777         self.current_ranges = ranges
    778         self.current_frame = element

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\plotting\plot.py in compute_ranges(self, obj, key, ranges)
    350             if (not (axiswise and not isinstance(obj, HoloMap)) or
    351                 (not framewise and isinstance(obj, HoloMap))):
--> 352                 self._compute_group_range(group, elements, ranges)
    353         self.ranges.update(ranges)
    354         return ranges

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\plotting\plot.py in _compute_group_range(group, elements, ranges)
    410             if isinstance(el, (Empty, Table)): continue
    411             for dim in el.dimensions('ranges', label=True):
--> 412                 dim_range = el.range(dim)
    413                 if dim not in group_ranges:
    414                     group_ranges[dim] = []

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\core\data\__init__.py in range(self, dim, data_range)
    247             return dim.range
    248         elif dim in self.dimensions() and data_range and len(self):
--> 249             lower, upper = self.interface.range(self, dim)
    250         else:
    251             lower, upper = (np.NaN, np.NaN)

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\holoviews\core\data\pandas.py in range(cls, columns, dimension)
    126                 column = column.sort(inplace=False)
    127             else:
--> 128                 column = column.sort_values()
    129             return column.iloc[0], column.iloc[-1]
    130         else:

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\series.py in sort_values(self, axis, ascending, inplace, kind, na_position)
   1861         idx = _default_index(len(self))
   1862 
-> 1863         argsorted = _try_kind_sort(arr[good])
   1864 
   1865         if is_list_like(ascending):

C:\Users\Krasnoshekov_KI\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\series.py in _try_kind_sort(arr)
   1847             try:
   1848                 # if kind==mergesort, it can fail for object dtype
-> 1849                 return arr.argsort(kind=kind)
   1850             except TypeError:
   1851                 # stable sort not available for object dtype

SystemError: <method-wrapper '__gt__' of Point object at 0x0000019DD6D34D68> returned a result with an error set

Out[92]:
:Points   [geometry,value]

At the same time, the following code works correctly:

gdf.geometry = gdf.buffer(0.1)
gv.Polygons(gdf)

I'm on Python 3.6 (Anaconda distribution) on Windows 10.

In [1]: import holoviews as hv, geoviews as gv
In [2]: hv.__version__
Out[2]: 1.9.1-x-gc1d66c015
In [3]: gv.__version__
Out[3]: 1.4.2
@philippjfr
Copy link
Member

Yes, geopandas Points geometries are currently not supported directly, only path and polygon data can currently be plotted using the gv.Paths and gv.Polygons. Supporting a geopandas dataframe containing points is a reasonable feature request and probably wouldn't require a huge amount of effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants