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

Update CartoFrames to v1 #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PYTHONUNBUFFERED=1
ENV PIP_NO_CACHE_DIR=off
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
ENV PIP_DEFAULT_TIMEOUT=100
ENV POETRY_VERSION=0.12.14
ENV POETRY_VERSION=1.0.10
ENV PATH=$PATH:/usr/src/app

ARG ENVIRONMENT=prod
Expand All @@ -22,7 +22,7 @@ RUN set -ex ; \
apt-get update ; \
apt-get install -y --no-install-recommends git gcc ; \
pip install "poetry==$POETRY_VERSION" ; \
poetry config settings.virtualenvs.create false ; \
poetry config virtualenvs.create false ; \
poetry install --no-interaction --no-ansi $POETRY_INSTALL_EXTRA ; \
apt-get remove -y --purge git gcc ; \
apt-get autoremove -y ; \
Expand Down
25 changes: 11 additions & 14 deletions longitude/core/data_sources/carto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import cartoframes
from cartoframes import read_carto, to_carto
from cartoframes.auth import set_default_credentials

from carto.auth import APIKeyAuthClient
from carto.exceptions import CartoException
from carto.sql import BatchSQLClient, SQLClient
Expand Down Expand Up @@ -26,8 +28,8 @@ def __init__(self, user, api_key, options={}):
self.api_key = api_key
self.base_url = self._generate_base_url(user, self.base_url_option)

# Carto Context for DataFrame handling
self._carto_context = None
# Set Carto Context for DataFrame handling
self._set_credentials()

# Carto client for COPYs
self._copy_client = None
Expand All @@ -39,21 +41,16 @@ def __init__(self, user, api_key, options={}):
if self.batch:
self._batch_client = BatchSQLClient(self._auth_client)

@property
def cc(self):
def _set_credentials(self):
"""
Creates and returns a CartoContext object to work with Panda Dataframes
Sets the default credentials for the CARTO connection.
:return:
"""
# TODO: The CartoContext documentaton says that SSL must be disabled sometimes if an on
# premise host is used.
# We are not taking this into account. It would need to create a requests.Session()
# object, set its SSL to false and pass it to the CartoContext init.
if self._carto_context is None:
self._carto_context = cartoframes.CartoContext(
base_url=self.base_url, api_key=self.api_key
)
return self._carto_context
set_default_credentials(base_url=self.base_url, api_key=self.api_key)

def _generate_base_url(self, user, base_url_option):
if base_url_option:
Expand Down Expand Up @@ -110,10 +107,10 @@ def copy_from(self, data, filepath, to_table):
return self._copy_client.copyfrom_file_object(from_query, data)

def read_dataframe(self, table_name='', *args, **kwargs):
return self.cc.read(table_name=table_name, *args, **kwargs)
return read_carto(table_name, *args, **kwargs)

def query_dataframe(self, query='', *args, **kwargs):
return self.cc.query(query=query, *args, **kwargs)
return read_carto(query, *args, **kwargs)

def write_dataframe(self, df, table_name='', *args, **kwargs):
return self.cc.write(df=df, table_name=table_name, *args, **kwargs)
return to_carto(df, table_name, *args, **kwargs)
4 changes: 2 additions & 2 deletions longitude/samples/aiohttp_oauth2_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from aiohttp import web

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) # noqa
from longitude.tools.oauth.carto_oauth2_client_aiohttp import CartoOAuth2ClientAiohttp
from longitude.samples.config import config
from longitude.tools.oauth.carto_oauth2_client_aiohttp import CartoOAuth2ClientAiohttp # noqa
from longitude.samples.config import config # noqa

"""
Minimal Carto-OAuth2 working example.
Expand Down
4 changes: 2 additions & 2 deletions longitude/samples/carto_async_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import aiohttp # noqa

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) # noqa
from longitude.core.data_sources.carto_async import CartoAsyncDataSource
from longitude.samples.config import config
from longitude.core.data_sources.carto_async import CartoAsyncDataSource # noqa
from longitude.samples.config import config # noqa


async def query_1(ds):
Expand Down
6 changes: 3 additions & 3 deletions longitude/samples/carto_sample_with_ram_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) # noqa
from longitude.core.caches.ram import RamCache
from longitude.core.data_sources.carto import CartoDataSource
from longitude.samples.config import config
from longitude.core.caches.ram import RamCache # noqa
from longitude.core.data_sources.carto import CartoDataSource # noqa
from longitude.samples.config import config # noqa

# import logging
# logging.basicConfig(level=logging.DEBUG)
Expand Down
8 changes: 4 additions & 4 deletions longitude/samples/carto_sample_with_redis_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) # noqa
from longitude.core.common.helpers import DisabledCache
from longitude.core.caches.redis import RedisCache
from longitude.core.data_sources.carto import CartoDataSource
from longitude.samples.config import config
from longitude.core.common.helpers import DisabledCache # noqa
from longitude.core.caches.redis import RedisCache # noqa
from longitude.core.data_sources.carto import CartoDataSource # noqa
from longitude.samples.config import config # noqa

if __name__ == "__main__":

Expand Down
Loading