Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

josema/ch93710/fix-wrong-username-error #1687

Merged
merged 4 commits into from
Sep 4, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cartoframes/io/carto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to interact with the CARTO platform"""
import functools
import math

from pandas import DataFrame
Expand All @@ -21,7 +22,22 @@
CSV_TO_CARTO_RATIO = 1.4


def not_found():
def decorator_func(func):
@functools.wraps(func)
def wrapper_func(*args, **kwargs):
try:
return func(*args, **kwargs)

except CartoException:
log.error('User and/or table do not exist')

return wrapper_func
return decorator_func


@send_metrics('data_downloaded')
@not_found()
def read_carto(source, credentials=None, limit=None, retry_times=3, schema=None, index_col=None, decode_geom=True,
null_geom_value=None):
"""Read a table or a SQL query from the CARTO account.
Expand Down Expand Up @@ -74,6 +90,7 @@ def read_carto(source, credentials=None, limit=None, retry_times=3, schema=None,


@send_metrics('data_uploaded')
@not_found()
def to_carto(dataframe, table_name, credentials=None, if_exists='fail', geom_col=None, index=False, index_label=None,
cartodbfy=True, log_enabled=True, retry_times=3, max_upload_size=MAX_UPLOAD_SIZE_BYTES,
skip_quota_warning=False):
Expand Down Expand Up @@ -172,6 +189,7 @@ def to_carto(dataframe, table_name, credentials=None, if_exists='fail', geom_col
return table_name


@not_found()
def list_tables(credentials=None):
"""List all of the tables in the CARTO account.

Expand All @@ -189,6 +207,7 @@ def list_tables(credentials=None):
return context_manager.list_tables()


@not_found()
def has_table(table_name, credentials=None, schema=None):
"""Check if the table exists in the CARTO account.

Expand All @@ -213,6 +232,7 @@ def has_table(table_name, credentials=None, schema=None):
return context_manager.has_table(table_name, schema)


@not_found()
def delete_table(table_name, credentials=None, log_enabled=True):
"""Delete the table from the CARTO account.

Expand All @@ -238,6 +258,7 @@ def delete_table(table_name, credentials=None, log_enabled=True):
log.info('Table "{}" does not exist'.format(table_name))


@not_found()
def rename_table(table_name, new_table_name, credentials=None, if_exists='fail', log_enabled=True):
"""Rename a table in the CARTO account.

Expand Down Expand Up @@ -270,6 +291,7 @@ def rename_table(table_name, new_table_name, credentials=None, if_exists='fail',
log.info('Success! Table "{0}" renamed to table "{1}" correctly'.format(table_name, new_table_name))


@not_found()
def copy_table(table_name, new_table_name, credentials=None, if_exists='fail', log_enabled=True):
"""Copy a table into a new table in the CARTO account.

Expand Down Expand Up @@ -303,6 +325,7 @@ def copy_table(table_name, new_table_name, credentials=None, if_exists='fail', l
log.info('Success! Table "{0}" copied to table "{1}" correctly'.format(table_name, new_table_name))


@not_found()
def create_table_from_query(query, new_table_name, credentials=None, if_exists='fail', log_enabled=True):
"""Create a new table from an SQL query in the CARTO account.

Expand Down Expand Up @@ -334,6 +357,7 @@ def create_table_from_query(query, new_table_name, credentials=None, if_exists='
log.info('Success! Table "{0}" created correctly'.format(new_table_name))


@not_found()
def describe_table(table_name, credentials=None, schema=None):
"""Describe the table in the CARTO account.

Expand Down Expand Up @@ -372,6 +396,7 @@ def describe_table(table_name, credentials=None, schema=None):
}


@not_found()
def update_privacy_table(table_name, privacy, credentials=None, log_enabled=True):
"""Update the table information in the CARTO account.

Expand Down