Skip to content

Commit

Permalink
Merge branch 'feature/fix_enrichment_new_catalogue' of github.com:Car…
Browse files Browse the repository at this point in the history
…toDB/cartoframes into feature/fix_enrichment_new_catalogue
  • Loading branch information
Jesus89 committed Oct 23, 2019
2 parents 41372bf + 752847d commit 3155cf8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 53 deletions.
44 changes: 22 additions & 22 deletions cartoframes/data/enrichment/points_enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ def enrich_points(data, variables, data_geom_column='geometry', filters=dict(),
your points with our geographies. Extra columns as area and population will be provided
with the aims of normalize these columns.
Args:
data (:py:class:`Dataset <cartoframes.data.Dataset>`, DataFrame, GeoDataFrame):
a Dataset, DataFrame or GeoDataFrame object to be enriched.
variables (:py:class:`Variable <cartoframes.data.observatory.Catalog>`, CatalogList, list, str):
variable(s), discovered through Catalog, for enriching the `data` argument.
data_geom_column (str): string indicating the 4326 geometry column in `data`.
filters (dict, optional): dictionary with either a `column` key
with the name of the column to filter or a `value` value with the value to filter by.
Filters will be used using the `AND` operator
credentials (:py:class:`Credentials <cartoframes.auth.Credentials>`, optional):
credentials of user account. If not provided,
a default credentials (if set with :py:meth:`set_default_credentials
<cartoframes.auth.set_default_credentials>`) will attempted to be
used.
Returns:
A dataframe as the provided one but with the variables to enrich appended to it
Note that if the geometry of the `data` you provide intersects with more than one geometry
in the enrichment dataset, the number of rows of the returned dataframe could be different
than the `data` argument number of rows.
Examples:
Enrich a points dataset with Catalog classes:
Expand Down Expand Up @@ -55,28 +77,6 @@ def enrich_points(data, variables, data_geom_column='geometry', filters=dict(),
variables = Catalog().country('usa').category('demographics').datasets[0].variables
filters = {'do_date': '2019-09-01'}
dataset_enrich = enrichment.enrich_points(dataset, variables, filters)
Args:
data (:py:class:`Dataset <cartoframes.data.Dataset>`, DataFrame, GeoDataFrame):
a Dataset, DataFrame or GeoDataFrame object to be enriched.
variables (:py:class:`Variable <cartoframes.data.observatory.Catalog>`, CatalogList, list, str):
variable(s), discovered through Catalog, for enriching the `data` argument.
data_geom_column (str): string indicating the 4326 geometry column in `data`.
filters (dict, optional): dictionary with either a `column` key
with the name of the column to filter or a `value` value with the value to filter by.
Filters will be used using the `AND` operator
credentials (:py:class:`Credentials <cartoframes.auth.Credentials>`, optional):
credentials of user account. If not provided,
a default credentials (if set with :py:meth:`set_default_credentials
<cartoframes.auth.set_default_credentials>`) will attempted to be
used.
Returns:
A dataframe as the provided one but with the variables to enrich appended to it
Note that if the geometry of the `data` you provide intersects with more than one geometry
in the enrichment dataset, the number of rows of the returned dataframe could be different
than the `data` argument number of rows.
"""

data_enriched = enrich(_prepare_sql, data=data, variables=variables, data_geom_column=data_geom_column,
Expand Down
54 changes: 26 additions & 28 deletions cartoframes/data/enrichment/polygons_enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ def enrich_polygons(data, variables, agg_operators=dict(), data_geom_column='geo
dataset, the proportional part of the intersection will be used to interpolate the quantity of the
polygon value intersected, aggregating them with the operator provided by `agg_operators` argument.
Args:
data (Dataset, DataFrame, GeoDataFrame): a Dataset, DataFrame or GeoDataFrame object to be enriched.
variables (Variable, CatalogList, list, str): variable(s), discovered through Catalog,
for enriching the `data` argument.
agg_operators (dict, str, None, optional): dictionary with either a `column` key
with the name of the column to aggregate or a `operator` value with the operator to group by.
If `agg_operators`' dictionary is empty (default argument value) then aggregation operators
will be retrieved from metadata column.
If `agg_operators` is a string then all columns will be aggregated by this operator.
If `agg_operators` is `None` then no aggregations will be computed. All the values which
data geometry intersects with will be returned.
data_geom_column (str): string indicating the 4326 geometry column in `data`.
filters (dict, optional): dictionary with either a `column` key
with the name of the column to filter or a `value` value with the value to filter by.
credentials (:py:class:`Credentials <cartoframes.auth.Credentials>`, optional):
credentials of user account. If not provided,
a default credentials (if set with :py:meth:`set_default_credentials
<cartoframes.auth.set_default_credentials>`) will attempted to be
used.
Returns:
A dataframe as the provided one but with the variables to enrich appended to it
Note that if the geometry of the `data` you provide intersects with more than one geometry
in the enrichment dataset, the number of rows of the returned dataframe could be different
than the `data` argument number of rows.
Examples:
Expand Down Expand Up @@ -96,34 +122,6 @@ def enrich_polygons(data, variables, agg_operators=dict(), data_geom_column='geo
agg_operators = None
dataset_enrich = enrichment.enrich_polygons(dataset, variables, agg_operators=agg_operators)
Args:
data (Dataset, DataFrame, GeoDataFrame): a Dataset, DataFrame or GeoDataFrame object to be enriched.
variables (Variable, CatalogList, list, str): variable(s), discovered through Catalog,
for enriching the `data` argument.
agg_operators (dict, str, None, optional): dictionary with either a `column` key
with the name of the column to aggregate or a `operator` value with the operator to group by.
If `agg_operators`' dictionary is empty (default argument value) then aggregation operators
will be retrieved from metadata column.
If `agg_operators` is a string then all columns will be aggregated by this operator.
If `agg_operators` is `None` then no aggregations will be computed. All the values which
data geometry intersects with will be returned.
data_geom_column (str): string indicating the 4326 geometry column in `data`.
filters (dict, optional): dictionary with either a `column` key
with the name of the column to filter or a `value` value with the value to filter by.
credentials (:py:class:`Credentials <cartoframes.auth.Credentials>`, optional):
credentials of user account. If not provided,
a default credentials (if set with :py:meth:`set_default_credentials
<cartoframes.auth.set_default_credentials>`) will attempted to be
used.
Returns:
A dataframe as the provided one but with the variables to enrich appended to it
Note that if the geometry of the `data` you provide intersects with more than one geometry
in the enrichment dataset, the number of rows of the returned dataframe could be different
than the `data` argument number of rows.
"""

data_enriched = enrich(_prepare_sql, data=data, variables=variables, agg_operators=agg_operators,
Expand Down
4 changes: 2 additions & 2 deletions cartoframes/viz/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ def _check_type(self, _type):
if _type and _type not in constants.LEGEND_TYPES:
raise ValueError(
'Legend type "{}" is not valid. Valid legend types are: {}.'.format(
', '.join(_type, constants.LEGEND_TYPES)
_type, ', '.join(constants.LEGEND_TYPES)
))

def _check_prop(self, _prop):
if _prop and _prop not in constants.LEGEND_PROPERTIES:
raise ValueError(
'Legend property "{}" is not valid. Valid legend properties are: {}.'.format(
', '.join(_prop, constants.LEGEND_PROPERTIES)
_prop, ', '.join(constants.LEGEND_PROPERTIES)
))

def _infer_prop(self, _type):
Expand Down
7 changes: 6 additions & 1 deletion docs/includes/data_enrichment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ Data Enrichment
---------------

With CARTOframes it is possible to enrich your data by using our `Data Observatory <#data-observatory>`__
Catalog through the enrichment methods.
Catalogue through the enrichment methods.

**Important:** Since the data enrichment depends on the Data Observatory 2.0,
is only accessible to selected CARTO Enterprise users in a private beta.
We're still open to more beta testers, so if you're interested,
`please get in touch. <#https://carto.com/contact/?campaign_details=data-observatory-betatester>`__

.. automodule:: cartoframes.data.enrichment
:members:
Expand Down
4 changes: 4 additions & 0 deletions docs/includes/data_observatory.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Data Observatory
----------------

**Important:** The new Data Observatory 2.0 is accessible to selected CARTO Enterprise
users in a private beta. We're still open to more beta testers, so if you're interested,
`please get in touch. <#https://carto.com/contact/?campaign_details=data-observatory-betatester>`__

.. automodule:: cartoframes.data.observatory
:members:
:member-order: bysource
Expand Down

0 comments on commit 3155cf8

Please sign in to comment.