Skip to content

Commit 0027393

Browse files
authored
Merge pull request #270 from CartoDB/v0.3.0b5
Version bump: v0.3.0b5
2 parents 08ce3f5 + 4685cc3 commit 0027393

28 files changed

+851
-469
lines changed

cartoframes/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.4b4'
1+
__version__ = '0.3.0b5'

cartoframes/context.py

+41-28
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,18 @@
5858
class CartoContext(object):
5959
"""CartoContext class for authentication with CARTO and high-level operations
6060
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.
6567
6668
Manages connections with CARTO for data and map operations. Modeled
6769
after `SparkContext
6870
<https://jaceklaskowski.gitbooks.io/mastering-apache-spark/content/spark-sparkcontext.html>`__.
6971
70-
Example:
71-
Create a CartoContext object::
72-
73-
import cartoframes
74-
cc = cartoframes.CartoContext(BASEURL, APIKEY)
75-
76-
Attrs:
72+
Attributes:
7773
creds (cartoframes.Credentials): :obj:`Credentials` instance
7874
7975
Args:
@@ -92,6 +88,12 @@ class CartoContext(object):
9288
Returns:
9389
:obj:`CartoContext`: A CartoContext object that is authenticated
9490
against the user's CARTO account.
91+
92+
Example:
93+
Create a CartoContext object::
94+
95+
import cartoframes
96+
cc = cartoframes.CartoContext(BASEURL, APIKEY)
9597
"""
9698
def __init__(self, base_url=None, api_key=None, creds=None, session=None,
9799
verbose=0):
@@ -118,24 +120,28 @@ def _is_org_user(self):
118120

119121
def read(self, table_name, limit=None, index='cartodb_id',
120122
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.
129124
130125
Args:
131126
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.
134129
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/>`__.
135134
136135
Returns:
137136
pandas.DataFrame: DataFrame representation of `table_name` from
138137
CARTO.
138+
139+
Example:
140+
.. code:: python
141+
142+
import cartoframes
143+
cc = cartoframes.CartoContext(BASEURL, APIKEY)
144+
df = cc.read('acadia_biodiversity')
139145
"""
140146
query = 'SELECT * FROM "{table_name}"'.format(table_name=table_name)
141147
if limit is not None:
@@ -572,15 +578,21 @@ def query(self, query, table_name=None, decode_geom=False):
572578
operations (creating/dropping tables, adding columns, updates, etc.).
573579
574580
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.
576583
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+
579591
Returns:
580592
pandas.DataFrame: DataFrame representation of query supplied.
581593
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.
584596
"""
585597
self._debug_print(query=query)
586598
if table_name:
@@ -695,8 +707,9 @@ def map(self, layers=None, interactive=True,
695707
``interactive`` is ``False``.
696708
697709
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.
700713
"""
701714
# TODO: add layers preprocessing method like
702715
# layers = process_layers(layers)

cartoframes/layer.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Layer classes for map creation. See examples in `layer.Layer
22
<#layer.Layer>`__ and `layer.QueryLayer <#layer.QueryLayer>`__
3-
for example usage.
3+
for example usage for data layers. See `layer.BaseMap <#layer.BaseMap>`__ for
4+
basemap layers.
45
"""
56

67
import pandas as pd
@@ -194,6 +195,7 @@ class QueryLayer(AbstractLayer):
194195
195196
If `color` is a :obj:`dict`, the following keys are options, with
196197
values described:
198+
197199
- column (`str`): Column used for the basis of styling
198200
- scheme (`dict`, optional): Scheme such as `styling.sunset(7)`
199201
from the `styling module <#module-styling>`__ of cartoframes that

docs/_sources/index.rst.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@
99
:maxdepth: 2
1010
:caption: Contents:
1111

12+
modules
13+
1214
CARTOFrames Functionality
1315
=========================
1416

1517
CartoContext
1618
------------
1719
.. autoclass:: context.CartoContext
18-
:members:
20+
:member-order: bysource
21+
:members: read, query, delete, map, data_augment
22+
23+
.. automethod:: write(df, table_name, temp_dir=SYSTEM_TMP_PATH, overwrite=False, lnglat=None, encode_geom=False, geom_col=None, \*\*kwargs)
1924

2025
Map Layer Classes
2126
-----------------
2227
.. automodule:: layer
23-
:members:
28+
:members: BaseMap, Layer, QueryLayer
2429

2530
Map Styling Functions
2631
---------------------
@@ -43,3 +48,5 @@ Indices and tables
4348
* :ref:`genindex`
4449
* :ref:`modindex`
4550
* :ref:`search`
51+
52+
:Version: |version|

docs/_static/basic.css

+5-1
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,14 @@ dd {
445445
margin-left: 30px;
446446
}
447447

448-
dt:target, .highlighted {
448+
dt:target, span.highlighted {
449449
background-color: #fbe54e;
450450
}
451451

452+
rect.highlighted {
453+
fill: #fbe54e;
454+
}
455+
452456
dl.glossary dt {
453457
font-weight: bold;
454458
font-size: 1.1em;

docs/_static/doctools.js

+38-14
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jQuery.urlencode = encodeURIComponent;
4545
* it will always return arrays of strings for the value parts.
4646
*/
4747
jQuery.getQueryParameters = function(s) {
48-
if (typeof s == 'undefined')
48+
if (typeof s === 'undefined')
4949
s = document.location.search;
5050
var parts = s.substr(s.indexOf('?') + 1).split('&');
5151
var result = {};
@@ -66,29 +66,53 @@ jQuery.getQueryParameters = function(s) {
6666
* span elements with the given class name.
6767
*/
6868
jQuery.fn.highlightText = function(text, className) {
69-
function highlight(node) {
70-
if (node.nodeType == 3) {
69+
function highlight(node, addItems) {
70+
if (node.nodeType === 3) {
7171
var val = node.nodeValue;
7272
var pos = val.toLowerCase().indexOf(text);
7373
if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) {
74-
var span = document.createElement("span");
75-
span.className = className;
74+
var span;
75+
var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg");
76+
if (isInSVG) {
77+
span = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
78+
} else {
79+
span = document.createElement("span");
80+
span.className = className;
81+
}
7682
span.appendChild(document.createTextNode(val.substr(pos, text.length)));
7783
node.parentNode.insertBefore(span, node.parentNode.insertBefore(
7884
document.createTextNode(val.substr(pos + text.length)),
7985
node.nextSibling));
8086
node.nodeValue = val.substr(0, pos);
87+
if (isInSVG) {
88+
var bbox = span.getBBox();
89+
var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
90+
rect.x.baseVal.value = bbox.x;
91+
rect.y.baseVal.value = bbox.y;
92+
rect.width.baseVal.value = bbox.width;
93+
rect.height.baseVal.value = bbox.height;
94+
rect.setAttribute('class', className);
95+
var parentOfText = node.parentNode.parentNode;
96+
addItems.push({
97+
"parent": node.parentNode,
98+
"target": rect});
99+
}
81100
}
82101
}
83102
else if (!jQuery(node).is("button, select, textarea")) {
84103
jQuery.each(node.childNodes, function() {
85-
highlight(this);
104+
highlight(this, addItems);
86105
});
87106
}
88107
}
89-
return this.each(function() {
90-
highlight(this);
108+
var addItems = [];
109+
var result = this.each(function() {
110+
highlight(this, addItems);
91111
});
112+
for (var i = 0; i < addItems.length; ++i) {
113+
jQuery(addItems[i].parent).before(addItems[i].target);
114+
}
115+
return result;
92116
};
93117

94118
/*
@@ -131,21 +155,21 @@ var Documentation = {
131155
* i18n support
132156
*/
133157
TRANSLATIONS : {},
134-
PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; },
158+
PLURAL_EXPR : function(n) { return n === 1 ? 0 : 1; },
135159
LOCALE : 'unknown',
136160

137161
// gettext and ngettext don't access this so that the functions
138162
// can safely bound to a different name (_ = Documentation.gettext)
139163
gettext : function(string) {
140164
var translated = Documentation.TRANSLATIONS[string];
141-
if (typeof translated == 'undefined')
165+
if (typeof translated === 'undefined')
142166
return string;
143-
return (typeof translated == 'string') ? translated : translated[0];
167+
return (typeof translated === 'string') ? translated : translated[0];
144168
},
145169

146170
ngettext : function(singular, plural, n) {
147171
var translated = Documentation.TRANSLATIONS[singular];
148-
if (typeof translated == 'undefined')
172+
if (typeof translated === 'undefined')
149173
return (n == 1) ? singular : plural;
150174
return translated[Documentation.PLURALEXPR(n)];
151175
},
@@ -216,7 +240,7 @@ var Documentation = {
216240
var src = $(this).attr('src');
217241
var idnum = $(this).attr('id').substr(7);
218242
$('tr.cg-' + idnum).toggle();
219-
if (src.substr(-9) == 'minus.png')
243+
if (src.substr(-9) === 'minus.png')
220244
$(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
221245
else
222246
$(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
@@ -248,7 +272,7 @@ var Documentation = {
248272
var path = document.location.pathname;
249273
var parts = path.split(/\//);
250274
$.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
251-
if (this == '..')
275+
if (this === '..')
252276
parts.pop();
253277
});
254278
var url = parts.join('/');

docs/_static/searchtools.js

+3
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ var Search = {
540540
});
541541
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
542542
var suffix = DOCUMENTATION_OPTIONS.SOURCELINK_SUFFIX;
543+
if (suffix === undefined) {
544+
suffix = '.txt';
545+
}
543546
$.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' + item[5] + (item[5].slice(-suffix.length) === suffix ? '' : suffix),
544547
dataType: "text",
545548
complete: function(jqxhr, textstatus) {

0 commit comments

Comments
 (0)