Skip to content

Commit

Permalink
Merge pull request #1327 from CartoDB/1319-fix-dataobsclient
Browse files Browse the repository at this point in the history
Fix DataObsClient
  • Loading branch information
Jesus89 committed Dec 11, 2019
2 parents 4e76bf1 + a22fdbd commit 9ee1def
Show file tree
Hide file tree
Showing 6 changed files with 2,046 additions and 154 deletions.
2 changes: 1 addition & 1 deletion cartoframes/core/managers/context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def copy_from(self, cdf, table_name, if_exists='fail', cartodbfy=True, log_enabl
# 'append'
pass

return self._copy_from(cdf, table_name, columns)
self._copy_from(cdf, table_name, columns)

def create_table_from_query(self, table_name, query, if_exists, cartodbfy=True, log_enabled=True):
schema = self.get_schema()
Expand Down
17 changes: 9 additions & 8 deletions cartoframes/data/clients/data_obs_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from carto.exceptions import CartoException

from ...core.managers.context_manager import ContextManager
from ...io.carto import read_carto
from ...io.carto import read_carto, to_carto
from ...utils import utils


Expand Down Expand Up @@ -63,7 +63,7 @@ def boundaries(self, boundary=None, region=None, decode_geom=False,
creds = Credentials('user name', 'api key')
do = DataObsClient(creds)
au_boundaries = do.boundaries(region='Australia')
au_boundaries.dataframe[['geom_name', 'geom_id']]
au_boundaries[['geom_name', 'geom_id']]
Get the boundaries for Australian Postal Areas and map them.
Expand Down Expand Up @@ -328,7 +328,7 @@ def discovery(self, region, keywords=None, regex=None, time=None,
Returns:
pandas.DataFrame:
A dataframe of the complete metadata model for specific measures based
A DataFrame of the complete metadata model for specific measures based
on the search parameters.
Raises:
Expand Down Expand Up @@ -477,7 +477,7 @@ def discovery(self, region, keywords=None, regex=None, time=None,
numers=numers,
quantiles=quantiles).strip()
utils.debug_print(self._verbose, query=query)
return self._fetch(query, decode_geom=True).dataframe
return pd.DataFrame(self._fetch(query, decode_geom=True))

def augment(self, table_name, metadata, persist_as=None, how='the_geom'):
"""Get an augmented CARTO dataset with `Data Observatory
Expand Down Expand Up @@ -594,7 +594,7 @@ def augment(self, table_name, metadata, persist_as=None, how='the_geom'):
' numeric, timespan_rownum numeric)',
)).format(table_name=table_name,
meta=json.dumps(metadata).replace('\'', '\'\''))
_meta = self._fetch(query).dataframe
_meta = pd.DataFrame(self._fetch(query))

if _meta.shape[0] == 0:
raise ValueError('There are no valid metadata entries. Check '
Expand Down Expand Up @@ -655,10 +655,11 @@ def augment(self, table_name, metadata, persist_as=None, how='the_geom'):

return self._fetch(query, decode_geom=False, table_name=persist_as)

def _fetch(self, query, table_name=None):
cdf = read_carto(query, self._credentials)
def _fetch(self, query, decode_geom=False, table_name=None):
cdf = read_carto(query, self._credentials, decode_geom=decode_geom)
if table_name:
cdf.to_carto(table_name, self._credentials)
to_carto(cdf, table_name, self._credentials,
geom_col='the_geom', if_exists='replace', log_enabled=False)
return cdf

def _geom_type(self, table):
Expand Down
1 change: 1 addition & 0 deletions docs/cartoframes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
.. include:: includes/utils.rst
.. include:: includes/data_observatory.rst
.. include:: includes/data_services.rst
.. include:: includes/data_clients.rst
.. include:: includes/viz.rst
.. include:: includes/exceptions.rst
8 changes: 8 additions & 0 deletions docs/includes/data_clients.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Data Clients
------------

.. automodule:: cartoframes.data.clients
:members:
:member-order: bysource
:undoc-members:
:show-inheritance:

0 comments on commit 9ee1def

Please sign in to comment.