cartoframes.utils module

general utility functions

cartoframes.utils.cssify(css_dict)

Function to get CartoCSS from Python dicts

cartoframes.utils.df2pg_schema(dataframe, pgcolnames)

Print column names with PostgreSQL schema for the SELECT statement of a SQL query

cartoframes.utils.dict_items(indict)

function for iterating through dict items compatible with py2 and 3

Parameters:indict (dict) – Dictionary that will be turned into items iterator
cartoframes.utils.dtypes2pg(dtype)

Returns equivalent PostgreSQL type for input dtype

cartoframes.utils.importify_params(param_arg)

Convert parameter arguments to what CARTO’s Import API expects

cartoframes.utils.join_url(*parts)

join parts of URL into complete url

cartoframes.utils.minify_sql(lines)

eliminate whitespace in sql queries

cartoframes.utils.norm_colname(colname)

Given an arbitrary column name, translate to a SQL-normalized column name a la CARTO’s Import API will translate to

Examples
  • ‘Field: 2’ -> ‘field_2’
  • ‘2 Items’ -> ‘_2_items’
Parameters:colname (str) – Column name that will be SQL normalized
Returns:SQL-normalized column name
Return type:str
cartoframes.utils.normalize_colnames(columns)

SQL-normalize columns in dataframe to reflect changes made through CARTO’s SQL API.

Parameters:columns (list of str) – List of column names
Returns:Normalized column names
Return type:list of str
cartoframes.utils.pg2dtypes(pgtype)

Returns equivalent dtype for input pgtype.

cartoframes.utils.pgquote(string)

single-quotes a string if not None, else returns null

cartoframes.utils.safe_quotes(text, escape_single_quotes=False)

htmlify string

cartoframes.utils.temp_ignore_warnings(func)

Temporarily ignores warnings like those emitted by the carto python sdk

cartoframes.utils.unique_colname(suggested, existing)

Given a suggested column name and a list of existing names, returns a name that is not present at existing by prepending _ characters.