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

DataError with timedelta #536

Open
raybellwaves opened this issue Nov 4, 2021 · 3 comments
Open

DataError with timedelta #536

raybellwaves opened this issue Nov 4, 2021 · 3 comments

Comments

@raybellwaves
Copy link

ALL software version info

ipython 7.27.0
hvplot 0.7.3
geoviews 1.9.2
jupyterlab 3.2.1

Description of expected behavior and the observed behavior

geopandas.DataFrame gets passed to gv.Points and is displayed correct

Complete, minimal, self-contained example code that reproduces the issue

import geopandas as gpd
import geoviews as gv
import hvplot.pandas
import pandas as pd


df = pd.DataFrame(
    data={
        "time": pd.date_range("2000", freq="D", periods=3),
        "lon": [1, 2, 3],
        "lat": [1, 2, 3],
    }
)
df["timedelta"] = df["time"] - df["time"].min() # Uncomment this and works

gdf = gpd.GeoDataFrame(
    df,
    geometry=gpd.points_from_xy(df["lon"], df["lat"]),
    crs="epsg:4326",
)

gv.Points(gdf)

Stack traceback and/or browser JavaScript console output

DataError                                 Traceback (most recent call last)
~/miniconda3/envs/main/lib/python3.9/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/dimension.py in _repr_mimebundle_(self, include, exclude)
   1315         combined and returned.
   1316         """
-> 1317         return Store.render(self)
   1318 
   1319 

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/options.py in render(cls, obj)
   1403         data, metadata = {}, {}
   1404         for hook in hooks:
-> 1405             ret = hook(obj)
   1406             if ret is None:
   1407                 continue

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py in pprint_display(obj)
    280     if not ip.display_formatter.formatters['text/plain'].pprint:
    281         return None
--> 282     return display(obj, raw_output=True)
    283 
    284 

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py in display(obj, raw_output, **kwargs)
    250     elif isinstance(obj, (CompositeOverlay, ViewableElement)):
    251         with option_state(obj):
--> 252             output = element_display(obj)
    253     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
    254         with option_state(obj):

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py in wrapped(element)
    144         try:
    145             max_frames = OutputSettings.options['max_frames']
--> 146             mimebundle = fn(element, max_frames=max_frames)
    147             if mimebundle is None:
    148                 return {}, {}

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py in element_display(element, max_frames)
    190         return None
    191 
--> 192     return render(element)
    193 
    194 

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/ipython/display_hooks.py in render(obj, **kwargs)
     66         renderer = renderer.instance(fig='png')
     67 
---> 68     return renderer.components(obj, **kwargs)
     69 
     70 

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/plotting/renderer.py in components(self, obj, fmt, comm, **kwargs)
    408                 doc = Document()
    409                 with config.set(embed=embed):
--> 410                     model = plot.layout._render_model(doc, comm)
    411                 if embed:
    412                     return render_model(model, comm)

~/miniconda3/envs/main/lib/python3.9/site-packages/panel/viewable.py in _render_model(self, doc, comm)
    453         if comm is None:
    454             comm = state._comm_manager.get_server_comm()
--> 455         model = self.get_root(doc, comm)
    456 
    457         if config.embed:

~/miniconda3/envs/main/lib/python3.9/site-packages/panel/viewable.py in get_root(self, doc, comm, preprocess)
    510         """
    511         doc = init_doc(doc)
--> 512         root = self._get_model(doc, comm=comm)
    513         if preprocess:
    514             self._preprocess(root)

~/miniconda3/envs/main/lib/python3.9/site-packages/panel/layout/base.py in _get_model(self, doc, root, parent, comm)
    120         if root is None:
    121             root = model
--> 122         objects = self._get_objects(model, [], doc, root, comm)
    123         props = dict(self._init_params(), objects=objects)
    124         model.update(**self._process_param_change(props))

~/miniconda3/envs/main/lib/python3.9/site-packages/panel/layout/base.py in _get_objects(self, model, old_objects, doc, root, comm)
    110             else:
    111                 try:
--> 112                     child = pane._get_model(doc, root, model, comm)
    113                 except RerenderError:
    114                     return self._get_objects(model, current_objects[:i], doc, root, comm)

~/miniconda3/envs/main/lib/python3.9/site-packages/panel/pane/holoviews.py in _get_model(self, doc, root, parent, comm)
    237             plot = self.object
    238         else:
--> 239             plot = self._render(doc, comm, root)
    240 
    241         plot.pane = self

~/miniconda3/envs/main/lib/python3.9/site-packages/panel/pane/holoviews.py in _render(self, doc, comm, root)
    304                 kwargs['comm'] = comm
    305 
--> 306         return renderer.get_plot(self.object, **kwargs)
    307 
    308     def _cleanup(self, root):

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/plotting/bokeh/renderer.py in get_plot(self_or_cls, obj, doc, renderer, **kwargs)
     71         combining the bokeh model with another plot.
     72         """
---> 73         plot = super(BokehRenderer, self_or_cls).get_plot(obj, doc, renderer, **kwargs)
     74         if plot.document is None:
     75             plot.document = Document() if self_or_cls.notebook_context else curdoc()

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/plotting/renderer.py in get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
    241             init_key = tuple(v if d is None else d for v, d in
    242                              zip(plot.keys[0], defaults))
--> 243             plot.update(init_key)
    244         else:
    245             plot = obj

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/plotting/plot.py in update(self, key)
    980     def update(self, key):
    981         if len(self) == 1 and ((key == 0) or (key == self.keys[0])) and not self.drawn:
--> 982             return self.initialize_plot()
    983         item = self.__getitem__(key)
    984         self.traverse(lambda x: setattr(x, '_updated', True))

~/miniconda3/envs/main/lib/python3.9/site-packages/geoviews/plotting/bokeh/plot.py in initialize_plot(self, ranges, plot, plots, source)
    111     def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
    112         opts = {} if isinstance(self, HvOverlayPlot) else {'source': source}
--> 113         fig = super(GeoPlot, self).initialize_plot(ranges, plot, plots, **opts)
    114         if self.geographic and self.show_bounds and not self.overlaid:
    115             from . import GeoShapePlot

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/plotting/bokeh/element.py in initialize_plot(self, ranges, plot, plots, source)
   1410         self.handles['plot'] = plot
   1411 
-> 1412         self._init_glyphs(plot, element, ranges, source)
   1413         if not self.overlaid:
   1414             self._update_plot(key, plot, style_element)

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/plotting/bokeh/element.py in _init_glyphs(self, plot, element, ranges, source)
   1354         else:
   1355             style = self.style[self.cyclic_index]
-> 1356             data, mapping, style = self.get_data(element, ranges, style)
   1357             current_id = element._plot_id
   1358 

~/miniconda3/envs/main/lib/python3.9/site-packages/geoviews/plotting/bokeh/plot.py in get_data(self, element, ranges, style)
    170     def get_data(self, element, ranges, style):
    171         if self._project_operation and self.geographic:
--> 172             element = self._project_operation(element, projection=self.projection)
    173         return super(GeoPlot, self).get_data(element, ranges, style)
    174 

~/miniconda3/envs/main/lib/python3.9/site-packages/param/parameterized.py in __new__(class_, *args, **params)
   3098         inst = class_.instance()
   3099         inst.param._set_name(class_.__name__)
-> 3100         return inst.__call__(*args,**params)
   3101 
   3102     def __call__(self,*args,**kw):

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/operation.py in __call__(self, element, **kwargs)
    218         kwargs['link_dataset'] = self._propagate_dataset
    219         kwargs['link_inputs'] = self.p.link_inputs
--> 220         return element.apply(self, **kwargs)
    221 
    222 

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/accessors.py in pipelined_call(*args, **kwargs)
     43 
     44             try:
---> 45                 result = __call__(*args, **kwargs)
     46 
     47                 if not in_method:

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/accessors.py in __call__(self, apply_function, streams, link_inputs, link_dataset, dynamic, per_element, **kwargs)
    202             if hasattr(apply_function, 'dynamic'):
    203                 inner_kwargs['dynamic'] = False
--> 204             new_obj = apply_function(self._obj, **inner_kwargs)
    205             if (link_dataset and isinstance(self._obj, Dataset) and
    206                 isinstance(new_obj, Dataset) and new_obj._dataset is None):

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/operation.py in __call__(self, element, **kwargs)
    212             elif ((self._per_element and isinstance(element, Element)) or
    213                   (not self._per_element and isinstance(element, ViewableElement))):
--> 214                 return self._apply(element)
    215         elif 'streams' not in kwargs:
    216             kwargs['streams'] = self.p.streams

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/operation.py in _apply(self, element, key)
    139             if not in_method:
    140                 element._in_method = True
--> 141         ret = self._process(element, key)
    142         if hasattr(element, '_in_method') and not in_method:
    143             element._in_method = in_method

~/miniconda3/envs/main/lib/python3.9/site-packages/geoviews/operation/projection.py in _process(self, element, key)
     38 
     39     def _process(self, element, key=None):
---> 40         return element.map(self._process_element, self.supported_types)
     41 
     42 

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/data/__init__.py in pipelined_fn(*args, **kwargs)
    203 
    204             try:
--> 205                 result = method_fn(*args, **kwargs)
    206                 if PipelineMeta.disable:
    207                     return result

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/data/__init__.py in map(self, *args, **kwargs)
   1220 
   1221     def map(self, *args, **kwargs):
-> 1222         return super(Dataset, self).map(*args, **kwargs)
   1223     map.__doc__ = LabelledData.map.__doc__
   1224 

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/dimension.py in map(self, map_fn, specs, clone)
    708             return deep_mapped
    709         else:
--> 710             return map_fn(self) if applies else self
    711 
    712 

~/miniconda3/envs/main/lib/python3.9/site-packages/geoviews/operation/projection.py in _process_element(self, element)
    161             return element.clone(crs=self.p.projection)
    162         xdim, ydim = element.dimensions()[:2]
--> 163         xs, ys = (element.dimension_values(i) for i in range(2))
    164         coordinates = self.p.projection.transform_points(element.crs, xs, ys)
    165         mask = np.isfinite(coordinates[:, 0])

~/miniconda3/envs/main/lib/python3.9/site-packages/geoviews/operation/projection.py in <genexpr>(.0)
    161             return element.clone(crs=self.p.projection)
    162         xdim, ydim = element.dimensions()[:2]
--> 163         xs, ys = (element.dimension_values(i) for i in range(2))
    164         coordinates = self.p.projection.transform_points(element.crs, xs, ys)
    165         mask = np.isfinite(coordinates[:, 0])

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/data/__init__.py in pipelined_fn(*args, **kwargs)
    203 
    204             try:
--> 205                 result = method_fn(*args, **kwargs)
    206                 if PipelineMeta.disable:
    207                     return result

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/data/__init__.py in dimension_values(self, dimension, expanded, flat)
   1103         """
   1104         dim = self.get_dimension(dimension, strict=True)
-> 1105         values = self.interface.values(self, dim, expanded, flat)
   1106         if dim.nodata is not None:
   1107             # Ensure nodata applies to boolean data in py2

~/miniconda3/envs/main/lib/python3.9/site-packages/geoviews/data/geopandas.py in values(cls, dataset, dimension, expanded, flat, compute, keep_index)
    375         values = []
    376         geom_type = data.geom_type.iloc[0]
--> 377         ds = dataset.clone(data.iloc[0].to_dict(), datatype=['geom_dictionary'])
    378         for i, row in data.iterrows():
    379             ds.data = row.to_dict()

~/miniconda3/envs/main/lib/python3.9/site-packages/geoviews/element/geo.py in clone(self, data, shared_data, new_type, *args, **overrides)
    115         if 'crs' not in overrides and (not new_type or isinstance(new_type, _Element)):
    116             overrides['crs'] = self.crs
--> 117         return super(_Element, self).clone(data, shared_data, new_type,
    118                                            *args, **overrides)
    119 

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/data/__init__.py in clone(self, data, shared_data, new_type, link, *args, **overrides)
   1209             overrides['dataset'] = self.dataset
   1210 
-> 1211         return super(Dataset, self).clone(
   1212             data, shared_data, new_type, *args, **overrides
   1213         )

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/dimension.py in clone(self, data, shared_data, new_type, link, *args, **overrides)
    574         # Apply name mangling for __ attribute
    575         pos_args = getattr(self, '_' + type(self).__name__ + '__pos_params', [])
--> 576         return clone_type(data, *args, **{k:v for k,v in settings.items()
    577                                           if k not in pos_args})
    578 

~/miniconda3/envs/main/lib/python3.9/site-packages/geoviews/element/geo.py in __init__(self, data, kdims, vdims, **kwargs)
    108         elif isinstance(data, _Element):
    109             kwargs['crs'] = data.crs
--> 110         super(_Element, self).__init__(data, kdims=kdims, vdims=vdims, **kwargs)
    111 
    112 

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/element/selection.py in __init__(self, *args, **kwargs)
     19 
     20     def __init__(self, *args, **kwargs):
---> 21         super(SelectionIndexExpr, self).__init__(*args, **kwargs)
     22         self._index_skip = False
     23 

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/data/__init__.py in __init__(self, data, kdims, vdims, **kwargs)
    339 
    340         validate_vdims = kwargs.pop('_validate_vdims', True)
--> 341         initialized = Interface.initialize(type(self), data, kdims, vdims,
    342                                            datatype=kwargs.get('datatype'))
    343         (data, self.interface, dims, extra_kws) = initialized

~/miniconda3/envs/main/lib/python3.9/site-packages/holoviews/core/data/interface.py in initialize(cls, eltype, data, kdims, vdims, datatype)
    269                                   % (intfc.__name__, e))
    270                 error = ' '.join([error, priority_error])
--> 271                 raise six.reraise(DataError, DataError(error, intfc), sys.exc_info()[2])
    272             raise DataError(error)
    273 

~/miniconda3/envs/main/lib/python3.9/site-packages/six.py in reraise(tp, value, tb)
    717             if value.__traceback__ is not tb:
    718                 raise value.with_traceback(tb)
--> 719             raise value
    720         finally:
    721             value = None

DataError: None of the available storage backends were able to support the supplied data format. GeomDictInterface raised following error:

 DictInterface expects data for each column to be flat.

GeomDictInterface expects tabular data, for more information on supported datatypes see http://holoviews.org/user_guide/Tabular_Datasets.html
@maximlt maximlt changed the title DataError with timedelta when hvplot.pandas imported DataError with timedelta Nov 4, 2021
@maximlt
Copy link
Member

maximlt commented Nov 4, 2021

Thanks for this report, I edited the title since I'm able to reproduce it without hvplot being involved at all.

import geopandas as gpd
import geoviews as gv
import pandas as pd
gv.extension('bokeh')

df = pd.DataFrame(
    data={
        "time": pd.date_range("2000", freq="D", periods=3),
        "lon": [1, 2, 3],
        "lat": [1, 2, 3],
    }
)
df["timedelta"] = df["time"] - df["time"].min() # Uncomment this and works

gdf = gpd.GeoDataFrame(
    df,
    geometry=gpd.points_from_xy(df["lon"], df["lat"]),
    crs="epsg:4326",
)

gv.Points(gdf)

@maximlt
Copy link
Member

maximlt commented Nov 24, 2021

A simple workaround:

gv.points(gdf, vdims=[])

@ahuang11
Copy link
Collaborator

ahuang11 commented Aug 1, 2024

Not sure if it's a bug because there's 4 dims

Nevermind, I remembered holoviews behavior incorrectly

This works

import geopandas as gpd
import geoviews as gv
import pandas as pd
import holoviews as hv
gv.extension('bokeh')

df = pd.DataFrame(
    data={
        "time": pd.date_range("2000", freq="D", periods=3),
        "lon": [1, 2, 3],
        "lat": [1, 2, 3],
    }
)
df["timedelta"] = df["time"] - df["time"].min()

hv.Points(df)

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

3 participants