Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
path += "/all/{}.vertica".format(name)
file = open(path, "r")
except:
raise Exception("No auto connection is available. To create an auto connection, use the new_auto_connection function of the verticapy.connections.connect module.")
dsn = file.read()
dsn = dsn.split("\n")
if (dsn[0] == "vertica_python"):
import vertica_python
conn = vertica_python.connect(** {"host": dsn[1], "port": dsn[2], "database": dsn[3], "user": dsn[4], "password": dsn[5]}, autocommit = True)
elif (dsn[0] == "pyodbc"):
import pyodbc
conn = pyodbc.connect(dsn[1], autocommit = True)
elif (dsn[0] == "jaydebeapi"):
import jaydebeapi
jdbc_driver_name = "com.vertica.jdbc.Driver"
jdbc_driver_loc = os.path.dirname(verticapy.__file__) + "/connections/vertica-jdbc-9.3.1-0.jar"
conn = jaydebeapi.connect(jdbc_driver_name, dsn[1], {'user': dsn[2], 'password': dsn[3]}, jars = jdbc_driver_loc)
else:
raise Exception("The auto connection format is incorrect. To create a new auto connection, use the new_auto_connection function of the verticapy.connections.connect module.")
return(conn)
#---#
def vHelp():
"""
---------------------------------------------------------------------------
VERTICAPY Interactive Help (FAQ).
"""
import verticapy
try:
from IPython.core.display import HTML, display, Markdown
except:
pass
path = os.path.dirname(verticapy.__file__)
img1 = "<center><img width="\"180px\"" src="https://raw.githubusercontent.com/vertica/VerticaPy/master/img/logo.png"></center>"
img2 = " ____________ ______\n"
img2 += " / __ `\\ / /\n"
img2 += " | \\/ / / /\n"
img2 += " |______ / / /\n"
img2 += " |____/ / /\n"
img2 += " _____________ / /\n"
img2 += " \\ / / /\n"
img2 += " \\ / / /\n"
img2 += " \\_______/ / /\n"
img2 += " ______ / /\n"
img2 += " \\ / / /\n"
img2 += " \\ / / /\n"
img2 += " \\/ / /\n"
img2 += " / /\n"
img2 += " / /\n"
load_winequality : Ingests the winequality dataset in the Vertica DB.
(Regression / Classification).
"""
check_types([
("schema", schema, [str], False),
("name", name, [str], False)])
if not(cursor):
cursor = read_auto_connect().cursor()
else:
check_cursor(cursor)
try:
vdf = vDataFrame(name, cursor, schema = schema)
except:
cursor.execute("CREATE TABLE {}.{}(\"Name\" Varchar(32), \"Form\" Varchar(32), \"Price\" Float);".format(str_column(schema), str_column(name)))
try:
path = os.path.dirname(verticapy.__file__) + "/learn/data/market.csv"
query = "COPY {}.{}(\"Form\", \"Name\", \"Price\") FROM {} DELIMITER ',' NULL '' ENCLOSED BY '\"' ESCAPE AS '\\' SKIP 1;".format(str_column(schema), str_column(name), "{}")
if ("vertica_python" in str(type(cursor))):
with open(path, "r") as fs:
cursor.copy(query.format('STDIN'), fs)
else:
cursor.execute(query.format("LOCAL '{}'".format(path)))
vdf = vDataFrame(name, cursor, schema = schema)
except:
cursor.execute("DROP TABLE {}.{}".format(str_column(schema), str_column(name)))
raise
return (vdf)
#---#
load_winequality : Ingests the winequality dataset in the Vertica DB.
(Regression / Classification).
"""
check_types([
("schema", schema, [str], False),
("name", name, [str], False)])
if not(cursor):
cursor = read_auto_connect().cursor()
else:
check_cursor(cursor)
try:
vdf = vDataFrame(name, cursor, schema = schema)
except:
cursor.execute("CREATE TABLE {}.{}(\"number\" Integer, \"date\" Date, \"state\" Varchar(32));".format(str_column(schema), str_column(name)))
try:
path = os.path.dirname(verticapy.__file__) + "/learn/data/amazon.csv"
query = "COPY {}.{}(\"number\", \"date\", \"state\") FROM {} DELIMITER ',' NULL '' ENCLOSED BY '\"' ESCAPE AS '\\' SKIP 1;".format(str_column(schema), str_column(name), "{}")
if ("vertica_python" in str(type(cursor))):
with open(path, "r") as fs:
cursor.copy(query.format('STDIN'), fs)
else:
cursor.execute(query.format("LOCAL '{}'".format(path)))
vdf = vDataFrame(name, cursor, schema = schema)
except:
cursor.execute("DROP TABLE {}.{}".format(str_column(schema), str_column(name)))
raise
return (vdf)
#---#
def available_auto_connection():
"""
---------------------------------------------------------------------------
Displays all the available auto connections.
Returns
-------
list
all the available auto connections.
See Also
--------
new_auto_connection : Saves a connection to automatically create DB cursors.
"""
path = os.path.dirname(verticapy.__file__) + "/connections/all/"
all_connections = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
all_connections = [elem.replace(".vertica", "") for elem in all_connections if ".vertica" in elem]
if (len(all_connections) == 1):
print("The only available connection is {}".format(all_connections[0]))
elif (all_connections):
print("The available connections are the following: {}".format(", ".join(all_connections)))
else:
print("No connections yet available. Use the new_auto_connection function to create your first one.")
return(all_connections)
#---#