Skip to content

Commit

Permalink
Merge pull request #1468 from CartoDB/release/1.0rc1
Browse files Browse the repository at this point in the history
Release/1.0rc1
  • Loading branch information
Jesus89 committed Jan 10, 2020
2 parents fcbee1c + f763e0c commit 367aad2
Show file tree
Hide file tree
Showing 30 changed files with 8,184 additions and 1,029 deletions.
54 changes: 44 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,54 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Next
[Migration Docs](/docs/developers/migrations/rc1.md)
## [1.0brc1] - 2020-01-10

[RC1 Migration Guide](/docs/developers/migrations/rc1.md)

### Added
- Add CLI subscription prompt (#1388)
- Add Data Enrichment e2e tests (#1365)
- Add utils.decode_geometry function (#1418)
- Add legend helpers (#1347, #1442)
- Add style helpers (#1345, #1410)
- Add popup_element helper (#1348)
- Add title and default_* params to Layer class (#1432)
- Add default_legend/widget/popup_element helpers (#1432)

### Changed
- Remove `popup` parameter and add `hover_popup` and `click_popup` in Layer (#1348)
- Add `popup_element` helpers (#1348)
- Refactor Widgets API (#1349)
- Add widget helpers (#1349)
- Refactor Legends API (#1347)
- Add legend helpers (#1345)
- Add style helpers (#1345)
- Check quota before using Data Services (#1370)
- Check dependencies on runtime (#1342, #1310)
- Return areas using aggregation None (#1295, #1394)
- Split update_table into rename_table and update_privacy_table (#1380)
- Review subscription messages (#1391, #1407, #1413)
- Remove aggregation in column names, and add variable limit (#1400)
- Update Enrichment filter API (#1374, #1390)
- Rename methods to_csv and to_dataframe (#1396)
- Move widgets helpers to viz (#1349)
- Replace popup param by popup_hover and popup_click in Layer class (#1348, #1432)
- Cartodbfy by default in to_carto (#1416)
- Improve Error messages/docs (#1409)
- Return a GeoDataFrame in every method (#1418)
- Support several agg (#1294)
- Support array in filters (#1406)

### Fixed
- Catch and show Enrichment errors (BQ) (#1364)
- Fix Geography geom_coverage docstring (#1405)
- Fix Geographies not filtered by provider (#1248)
- Fix /support/contribute section in docs (#1427)
- Fix date format when using Dataframes (#1358)
- Fix hover+click behaviour (#1458)
- Fix footer in widgets (#1432)
- Fix dependencies to run in Colab (#1453)

### Removed
- Remove default_legend param in Map
- Remove Python 2.7 support (#1324)
- Remove get from CatalogList (#1369)
- Remove CartoDataFrame class (#1418)
- Remove utils.table (#1461)
- Remove default_legend param in Map class (#1399)
- Remove Style, Legend, Widget and Popup classes from viz (#1399)

## [1.0b7] - 2019-12-13
### Added
Expand Down
155 changes: 5 additions & 150 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ CARTOframes

.. image:: https://travis-ci.org/CartoDB/cartoframes.svg
:target: https://travis-ci.org/CartoDB/CARTOframes
.. image:: https://img.shields.io/badge/pypi-v1.0b7-orange
:target: https://pypi.org/project/cartoframes/1.0b7
.. image:: https://img.shields.io/badge/pypi-v1.0rc1-orange
:target: https://pypi.org/project/cartoframes/1.0rc1

A Python package for integrating `CARTO <https://carto.com/>`__ maps, analysis, and data services into data science workflows.

Expand All @@ -15,14 +15,14 @@ Try it Out
==========

* Stable (v0.10.1): |stable|
* Beta (v1.0b7): |beta|
* Beta (v1.0rc1): |rc|
* Latest (develop branch): |develop|

.. |stable| image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/cartodb/cartoframes/v0.10.1?filepath=examples

.. |beta| image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/cartodb/cartoframes/v1.0b7?filepath=examples
:target: https://mybinder.org/v2/gh/cartodb/cartoframes/v1.0rc1?filepath=examples

.. |develop| image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/cartodb/cartoframes/develop?filepath=examples
Expand Down Expand Up @@ -54,149 +54,4 @@ More info

- Complete documentation: https://carto.com/developers/cartoframes/
- Source code: https://github.com/CartoDB/cartoframes
- Bug tracker / feature requests: https://github.com/CartoDB/cartoframes/issues

`cartoframes` users must have a CARTO API key for most `cartoframes` functionality. For example, writing DataFrames to an account, reading from private tables, and visualizing data on maps all require an API key. CARTO provides API keys for education and nonprofit uses, among others. Request access at support@carto.com. API key access is also given through `GitHub's Student Developer Pack <https://carto.com/blog/carto-is-part-of-the-github-student-pack>`__.

Install Instructions
====================

To install `cartoframes` on your machine, do the following to install the
latest version:

.. code:: bash
$ pip install cartoframes
To install the 1.0b7 beta version:

.. code:: bash
$ pip install cartoframes==1.0b7
`cartoframes` is continuously tested on Python versions 3.5, 3.6, and 3.7. It is recommended to use `cartoframes` in Jupyter Notebooks (`pip install jupyter`). See the example usage section below or notebooks in the `examples directory <https://github.com/CartoDB/cartoframes/tree/master/examples>`__ for using `cartoframes` in that environment.

Example usage
=============

Data workflow
-------------

Get table from CARTO, make changes in pandas, sync updates with CARTO:

.. code:: python
from cartoframes import read_carto, to_carto
from cartoframes.auth import set_default_credentials
# set your credentials
set_default_credentials(
username='your_user_name',
api_key='your API key'
)
# read a table from your CARTO account
gdf = read_carto('brooklyn_poverty_census_tracts')
# perform operations on you dataframe
gdf['poverty_per_pop'] = gdf['poverty_count'] / gdf['total_population']
# update CARTO table with all changes from this session
to_carto(gdf, table_name='brooklyn_poverty_census_tracts', if_exists='replace')
Map workflow
------------

Render Interactive Maps
^^^^^^^^^^^^^^^^^^^^^^^

Interactive vector maps can be created programmatically in CARTOframes. In addition to hosted tables and queries, these maps can also display geographic information in pandas DataFrames and geopandas GeoDataFrames. This means that these maps do not need to be tied to a CARTO account (i.e., no need for an API key).

.. code:: python
from cartoframes.viz import Layer, color_continuous_style
from cartoframes.auth import set_default_credentials
set_default_credentials('cartoframes')
# display map in a notebook
Layer('brooklyn_poverty', color_continuous_style('poverty_per_pop'))
Publish map to CARTO
^^^^^^^^^^^^^^^^^^^^

.. code:: python
from cartoframes.viz import Map, Layer, color_continuous_style
from cartoframes.auth import set_default_credentials
set_default_credentials(
base_url='https://your_user_name.carto.com',
api_key='your api key'
)
# display map in a notebook
bk_map = Map(Layer('brooklyn_poverty', color_continuous_style('poverty_per_pop')))
bk_map.publish('Brooklyn Poverty')
This will publish a map like `this one <https://cartoframes.carto.com/kuviz/2a7badc3-00b3-49d0-9bc8-3b138542cdcf>`__.

CARTO Credential Management
---------------------------

Typical usage
^^^^^^^^^^^^^

The most common way to input credentials into cartoframes is through the `set_default_credentials` method, as below. Replace `{your_user_name}` with your CARTO username and `{your_api_key}` with your API key, which you can find at ``https://{your_user_name}.carto.com/your_apps``.

.. code:: python
from cartoframes.auth import set_default_credentials
set_default_credentials(
filepath='your_creds_file.json'
)
# or
set_default_credentials(
username='{your_user_name}',
api_key='{your_api_key}'
)
When the data we’re going to use is public, we don’t need the api_key parameter, it’s automatically set to default_public:

.. code:: python
from cartoframes.auth import set_default_credentials
set_default_credentials('your_user_name')
You can also set your credentials using the `base_url` parameter:

.. code:: python
from cartoframes.auth import set_default_credentials
set_default_credentials(
base_url='https://{your_user_name}.carto.com',
api_key='{your_api_key}'
)
Save/update credentials for later use
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
from cartoframes.auth import Credentials
credentials = Credentials('{your_user_name}', '{your_api_key}')
credentials.save('path/file/creds.json') # save credentials for later use (not dependent on Python session)
Once you save your credentials, you can get started in future sessions more quickly:

.. code:: python
from cartoframes.auth import Credentials
credentials = Credentials.from_file('path/file/creds.json') # automatically loads credentials if previously saved
- Bug tracker / feature requests: https://github.com/CartoDB/cartoframes/issues
2 changes: 1 addition & 1 deletion binder/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cartoframes==1.0b7
cartoframes==1.0rc1
# Additional dependencies from examples
matplotlib
dask
Expand Down
2 changes: 1 addition & 1 deletion cartoframes/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0rc1.dev'
__version__ = '1.0rc1'
3 changes: 3 additions & 0 deletions cartoframes/assets/templates/viz/main_layout.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

<!-- External libraries -->

<!-- pako -->
<script src="https://libs.cartocdn.com/cartoframes/dependencies/pako_inflate.min.js"></script>

<!-- base64-js -->
<script src='https://libs.cartocdn.com/cartoframes/dependencies/base64.js'></script>
<!-- html2canvas -->
Expand Down
6 changes: 5 additions & 1 deletion cartoframes/data/observatory/catalog/subscriptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

from json.decoder import JSONDecodeError
from carto.do_subscriptions import DOSubscriptionManager, DOSubscriptionCreationManager


Expand Down Expand Up @@ -51,7 +52,10 @@ def fetch_subscriptions(credentials):
api_key_auth_client = credentials.get_api_key_auth_client()
do_manager = DOSubscriptionManager(api_key_auth_client)
if do_manager is not None:
return do_manager.all()
try:
return do_manager.all()
except JSONDecodeError:
return []
return []


Expand Down
10 changes: 9 additions & 1 deletion cartoframes/viz/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ class Layer:
south], [east, north]]. If not provided the bounds will be automatically
calculated to fit all features.
geom_col (str, optional): string indicating the geometry column name in the source `DataFrame`.
default_legend (bool, optional): flag to set the default legend. This only works when using a
style helper. Default True.
default_widget (bool, optional): flag to set the default widget. This only works when using a
style helper. Default False.
default_popup_hover (bool, optional): flag to set the default popup hover. This only works when using a
style helper. Default True.
default_popup_click (bool, optional): flag to set the default popup click. This only works when using a
style helper. Default False.
title (str, optional): title for the default legend, widget and popups.
Raises:
ValueError: if the source is not valid.
Expand Down
3 changes: 1 addition & 2 deletions cartoframes/viz/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Legend:
def __init__(self, legend_type=None, title=None, description=None,
footer=None, prop=None, variable='', dynamic=True):
self._check_type(legend_type)
self._check_prop(prop)
self._type = legend_type
self._title = title
self._description = description
Expand Down Expand Up @@ -54,8 +55,6 @@ def _get_prop(self, _type):
else:
_prop = self._prop

self._check_prop(_prop)

return constants.VIZ_PROPERTIES_MAP.get(_prop)

def _check_type(self, _type):
Expand Down
10 changes: 5 additions & 5 deletions cartoframes/viz/styles/size_bins_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def size_bins_style(value, method='quantiles', bins=5, breaks=None, size_range=N
Default is "quantiles".
bins (int, optional): Number of size classes (bins) for map. Default is 5.
breaks (list<int>, optional): Assign manual class break values.
size_range (int, optional): Min/max size array as a string. Default is
'[2, 14]' for point geometries and '[1, 10]' for lines.
size_range (list<int>, optional): Min/max size array as a string. Default is
[2, 14] for point geometries and [1, 10] for lines.
color (str, optional): Hex, rgb or named color value. Default is '#EE5D5A' for point geometries and
'#4CC8A3' for lines.
'#4CC8A3' for lines.
opacity (float, optional): Opacity value for point color and line features.
Default is 0.8.
Default is 0.8.
stroke_color (str, optional): Color of the stroke on point features.
Default is '#222'.
stroke_width (int, optional): Size of the stroke on point features.
Expand Down Expand Up @@ -49,7 +49,7 @@ def size_bins_style(value, method='quantiles', bins=5, breaks=None, size_range=N
data = {
'point': {
'color': 'opacity({0}, {1})'.format(
get_value(color, 'color', 'point'),
get_value(color, '#EE5D5A'),
get_value(opacity, 0.8)),
'width': 'ramp({0}(${1}, {2}), {3})'.format(
func, value, breaks or bins, size_range or [2, 14]),
Expand Down
10 changes: 5 additions & 5 deletions cartoframes/viz/styles/size_category_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def size_category_style(value, top=5, cat=None, size_range=None, color=None, opa
top (int, optional): Number of size categories. Default is 5. Values
can range from 1 to 16.
cat (list<str>, optional): Category list as a string.
size_range (str, optional): Min/max size array as a string. Default is
'[2, 20]' for point geometries and '[1, 10]' for lines.
size_range (list<int>, optional): Min/max size array as a string. Default is
[2, 20] for point geometries and [1, 10] for lines.
color (str, optional): hex, rgb or named color value.
Default is '#F46D43' for point geometries and '#4CC8A3' for lines.
Default is '#F46D43' for point geometries and '#4CC8A3' for lines.
opacity (float, optional): Opacity value for point color and line features.
Default is 0.8.
Default is 0.8.
stroke_color (str, optional): Color of the stroke on point features.
Default is '#222'.
stroke_width (int, optional): Size of the stroke on point features.
Expand All @@ -36,7 +36,7 @@ def size_category_style(value, top=5, cat=None, size_range=None, color=None, opa
data = {
'point': {
'color': 'opacity({0}, {1})'.format(
get_value(color, 'color', 'point'),
get_value(color, '#F46D43'),
get_value(opacity, 1)),
'width': 'ramp({0}(${1}, {2}), {3})'.format(
func, value, cat or top, size_range or [2, 20]),
Expand Down

0 comments on commit 367aad2

Please sign in to comment.