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

Add Dataframe visualization support #735

Closed
Jesus89 opened this issue Jun 5, 2019 · 3 comments
Closed

Add Dataframe visualization support #735

Jesus89 opened this issue Jun 5, 2019 · 3 comments
Assignees

Comments

@Jesus89
Copy link
Member

Jesus89 commented Jun 5, 2019

Map(Layer(df))

The Source object must convert df into gdf, so we need to convert the geometry first if required. Then it will be rendered as a VL GeoJSON source.

@djfan
Copy link
Contributor

djfan commented Jun 5, 2019

Tested some Dataset sources in Map. a worked well, but b and c didn't work.

Screen Shot 2019-06-05 at 1 50 07 PM

The error messages are:

b

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-157-ad2161e679d4> in <module>
      6                       'value': '$lat'}]},
      7           context=cc),
----> 8      Layer(b, {'color': 'blue'})
      9     ], 
     10     basemap=basemaps.positron)

~/anaconda3/lib/python3.6/site-packages/cartoframes/viz/layer.py in __init__(self, source, style, popup, legend, context)
     86         self.is_basemap = False
     87 
---> 88         self.source = _set_source(source, context)
     89         self.style = _set_style(style)
     90         self.popup = _set_popup(popup)

~/anaconda3/lib/python3.6/site-packages/cartoframes/viz/layer.py in _set_source(source, context)
    106     """Set a Source class from the input"""
    107     if isinstance(source, (str, list, dict, Dataset)):
--> 108         return Source(source, context)
    109     elif isinstance(source, Source):
    110         return source

~/anaconda3/lib/python3.6/site-packages/cartoframes/viz/source.py in __init__(self, data, context, bounds, schema)
    135 
    136         self.context = _get_context(self.dataset)
--> 137         self.geom_type = _get_geom_type(self.dataset)
    138         self.credentials = _get_credentials(self.dataset)
    139 

~/anaconda3/lib/python3.6/site-packages/cartoframes/viz/source.py in _get_geom_type(dataset)
    222 
    223 def _get_geom_type(dataset):
--> 224     return dataset.compute_geom_type() or Dataset.GEOM_TYPE_POINT

~/anaconda3/lib/python3.6/site-packages/cartoframes/dataset.py in compute_geom_type(self)
    314             return self._get_remote_geom_type(get_query(self))
    315         elif self.state == Dataset.STATE_LOCAL:
--> 316             return self._get_local_geom_type(self.gdf)
    317 
    318     def _get_remote_geom_type(self, query):

~/anaconda3/lib/python3.6/site-packages/cartoframes/dataset.py in _get_local_geom_type(self, gdf)
    331     def _get_local_geom_type(self, gdf):
    332         """Compute geom type of the local dataframe"""
--> 333         if len(gdf.geometry) > 0:
    334             geom_type = gdf.geometry[0].type
    335             if geom_type:

AttributeError: 'NoneType' object has no attribute 'geometry'

c

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-158-c1988cb37a5a> in <module>
      6                       'value': '$lat'}]},
      7           context=cc),
----> 8      Layer(c, {'color': 'blue'})
      9     ], 
     10     basemap=basemaps.positron)

~/anaconda3/lib/python3.6/site-packages/cartoframes/viz/layer.py in __init__(self, source, style, popup, legend, context)
     86         self.is_basemap = False
     87 
---> 88         self.source = _set_source(source, context)
     89         self.style = _set_style(style)
     90         self.popup = _set_popup(popup)

~/anaconda3/lib/python3.6/site-packages/cartoframes/viz/layer.py in _set_source(source, context)
    106     """Set a Source class from the input"""
    107     if isinstance(source, (str, list, dict, Dataset)):
--> 108         return Source(source, context)
    109     elif isinstance(source, Source):
    110         return source

~/anaconda3/lib/python3.6/site-packages/cartoframes/viz/source.py in __init__(self, data, context, bounds, schema)
    132 
    133     def __init__(self, data, context=None, bounds=None, schema=None):
--> 134         self._init_source(data, context, bounds, schema)
    135 
    136         self.context = _get_context(self.dataset)

~/anaconda3/lib/python3.6/site-packages/cartoframes/viz/source.py in _init_source(self, data, context, bounds, schema)
    153 
    154         elif isinstance(data, Dataset):
--> 155             self._init_source_dataset(data, bounds)
    156 
    157         else:

~/anaconda3/lib/python3.6/site-packages/cartoframes/viz/source.py in _init_source_dataset(self, data, bounds)
    176             self._set_source_query(self.dataset, bounds)
    177         elif self.dataset.state == Dataset.STATE_LOCAL:
--> 178             if self.dataset.gdf:
    179                 self._set_source_geojson(self.dataset, bounds)
    180             else:

~/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
   1574         raise ValueError("The truth value of a {0} is ambiguous. "
   1575                          "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1576                          .format(self.__class__.__name__))
   1577 
   1578     __bool__ = __nonzero__

ValueError: The truth value of a GeoDataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

cc @andy-esch

@Jesus89
Copy link
Member Author

Jesus89 commented Jun 6, 2019

Hi @djfan. Thanks for trying this branch. This is still WIP, sorry about not putting the tag.

I'll work today on the geometry detection, and after that, it should work for all the cases :)

@Jesus89 Jesus89 added this to the Release v0.11 milestone Jun 7, 2019
@Jesus89
Copy link
Member Author

Jesus89 commented Jun 10, 2019

Closed via #741

@Jesus89 Jesus89 closed this as completed Jun 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants