From 4b8ba808e7c741bb1ae26a12964cd8728d1b4346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Arroyo=20Torrens?= Date: Fri, 3 Apr 2020 13:38:09 +0200 Subject: [PATCH] Return table name in to_carto --- cartoframes/io/carto.py | 5 +++++ tests/unit/io/test_carto.py | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cartoframes/io/carto.py b/cartoframes/io/carto.py index 8e8ecdb44..f07892546 100644 --- a/cartoframes/io/carto.py +++ b/cartoframes/io/carto.py @@ -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 `. + 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. @@ -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. diff --git a/tests/unit/io/test_carto.py b/tests/unit/io/test_carto.py index 9077b01b1..338dc4c66 100644 --- a/tests/unit/io/test_carto.py +++ b/tests/unit/io/test_carto.py @@ -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):