Skip to content

Commit

Permalink
Merge pull request #1609 from CartoDB/jarroyo/ch66846/return-carto-ta…
Browse files Browse the repository at this point in the history
…ble-name-when-uploading-a

Return table name in to_carto
  • Loading branch information
Jesus89 committed Apr 3, 2020
2 parents dba6cac + 18790db commit 9f17774
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cartoframes/io/carto.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def to_carto(dataframe, table_name, credentials=None, if_exists='fail', geom_col
cartodbfy (bool, optional): convert the table to CARTO format. Default True. More info
`here <https://carto.com/developers/sql-api/guides/creating-tables/#create-tables>`.
Returns:
string: the table name normalized.
Raises:
ValueError: if the dataframe or table name provided are wrong or the if_exists param is not valid.
Expand Down Expand Up @@ -121,6 +124,8 @@ def to_carto(dataframe, table_name, credentials=None, if_exists='fail', geom_col
if log_enabled:
log.info('Success! Data uploaded to table "{}" correctly'.format(table_name))

return table_name


def has_table(table_name, credentials=None, schema=None):
"""Check if the table exists in the CARTO account.
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/io/test_carto.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,19 @@ def test_read_carto_decode_geom_false(mocker):

def test_to_carto(mocker):
# Given
table_name = '__table_name__'
cm_mock = mocker.patch.object(ContextManager, 'copy_from')
cm_mock.return_value = table_name
df = GeoDataFrame({'geometry': [Point([0, 0])]})

# When
to_carto(df, '__table_name__', CREDENTIALS)
norm_table_name = to_carto(df, table_name, CREDENTIALS)

# Then
assert cm_mock.call_args[0][1] == '__table_name__'
assert cm_mock.call_args[0][1] == table_name
assert cm_mock.call_args[0][2] == 'fail'
assert cm_mock.call_args[0][3] is True
assert norm_table_name == table_name


def test_to_carto_wrong_dataframe(mocker):
Expand Down

0 comments on commit 9f17774

Please sign in to comment.