58
58
class CartoContext (object ):
59
59
"""CartoContext class for authentication with CARTO and high-level operations
60
60
such as reading tables from CARTO into dataframes, writing dataframes to
61
- CARTO tables, and creating custom maps from dataframes and CARTO tables.
62
- Future methods interact with CARTO's services like
63
- `Data Observatory <https://carto.com/data-observatory>`__, and `routing,
64
- geocoding, and isolines <https://carto.com/location-data-services/>`__.
61
+ CARTO tables, creating custom maps from dataframes and CARTO tables, and
62
+ augmenting data using CARTO's `Data Observatory
63
+ <https://carto.com/data-observatory>`__. Future methods will interact with
64
+ CARTO's services like `routing, geocoding, and isolines
65
+ <https://carto.com/location-data-services/>`__, PostGIS backend for spatial
66
+ processing, and much more.
65
67
66
68
Manages connections with CARTO for data and map operations. Modeled
67
69
after `SparkContext
68
70
<https://jaceklaskowski.gitbooks.io/mastering-apache-spark/content/spark-sparkcontext.html>`__.
69
71
70
- Example:
71
- Create a CartoContext object::
72
-
73
- import cartoframes
74
- cc = cartoframes.CartoContext(BASEURL, APIKEY)
75
-
76
- Attrs:
72
+ Attributes:
77
73
creds (cartoframes.Credentials): :obj:`Credentials` instance
78
74
79
75
Args:
@@ -92,6 +88,12 @@ class CartoContext(object):
92
88
Returns:
93
89
:obj:`CartoContext`: A CartoContext object that is authenticated
94
90
against the user's CARTO account.
91
+
92
+ Example:
93
+ Create a CartoContext object::
94
+
95
+ import cartoframes
96
+ cc = cartoframes.CartoContext(BASEURL, APIKEY)
95
97
"""
96
98
def __init__ (self , base_url = None , api_key = None , creds = None , session = None ,
97
99
verbose = 0 ):
@@ -118,24 +120,28 @@ def _is_org_user(self):
118
120
119
121
def read (self , table_name , limit = None , index = 'cartodb_id' ,
120
122
decode_geom = False ):
121
- """Read tables from CARTO into pandas DataFrames.
122
-
123
- Example:
124
- .. code:: python
125
-
126
- import cartoframes
127
- cc = cartoframes.CartoContext(BASEURL, APIKEY)
128
- df = cc.read('acadia_biodiversity')
123
+ """Read a table from CARTO into a pandas DataFrames.
129
124
130
125
Args:
131
126
table_name (str): Name of table in user's CARTO account.
132
- limit (int, optional): Read only `` limit` ` lines from
133
- `` table_name`` . Defaults to `None`, which reads the full table.
127
+ limit (int, optional): Read only `limit` lines from
128
+ `table_name`. Defaults to `` None` `, which reads the full table.
134
129
index (str, optional): Not currently in use.
130
+ decode_geom (bool, optional): Decodes CARTO's geometries into a
131
+ `Shapely <https://github.com/Toblerity/Shapely>`__
132
+ object that can be used, for example, in `GeoPandas
133
+ <http://geopandas.org/>`__.
135
134
136
135
Returns:
137
136
pandas.DataFrame: DataFrame representation of `table_name` from
138
137
CARTO.
138
+
139
+ Example:
140
+ .. code:: python
141
+
142
+ import cartoframes
143
+ cc = cartoframes.CartoContext(BASEURL, APIKEY)
144
+ df = cc.read('acadia_biodiversity')
139
145
"""
140
146
query = 'SELECT * FROM "{table_name}"' .format (table_name = table_name )
141
147
if limit is not None :
@@ -572,15 +578,21 @@ def query(self, query, table_name=None, decode_geom=False):
572
578
operations (creating/dropping tables, adding columns, updates, etc.).
573
579
574
580
Args:
575
- query (str): Query to run against CARTO user database.
581
+ query (str): Query to run against CARTO user database. This data
582
+ will then be converted into a pandas DataFrame.
576
583
table_name (str, optional): If set, this will create a new
577
- table in the user's CARTO account that is the result of the
578
- query. Defaults to None (no table created).
584
+ table in the user's CARTO account that is the result of the
585
+ query. Defaults to None (no table created).
586
+ decode_geom (bool, optional): Decodes CARTO's geometries into a
587
+ `Shapely <https://github.com/Toblerity/Shapely>`__
588
+ object that can be used, for example, in `GeoPandas
589
+ <http://geopandas.org/>`__.
590
+
579
591
Returns:
580
592
pandas.DataFrame: DataFrame representation of query supplied.
581
593
Pandas data types are inferred from PostgreSQL data types.
582
- In the case of PostgreSQL date types, the data type 'object' is
583
- used.
594
+ In the case of PostgreSQL date types, dates are attempted to be
595
+ converted, but on failure a data type 'object' is used.
584
596
"""
585
597
self ._debug_print (query = query )
586
598
if table_name :
@@ -695,8 +707,9 @@ def map(self, layers=None, interactive=True,
695
707
``interactive`` is ``False``.
696
708
697
709
Returns:
698
- IPython.display.HTML: Interactive maps are rendered in an
699
- ``iframe``, while static maps are rendered in ``img`` tags.
710
+ IPython.display.HTML or matplotlib Axes: Interactive maps are
711
+ rendered as HTML in an `iframe`, while static maps are returned as
712
+ matplotlib Axes objects or IPython Image.
700
713
"""
701
714
# TODO: add layers preprocessing method like
702
715
# layers = process_layers(layers)
0 commit comments