kedro.io.SQLTableDataSet¶
-
class
kedro.io.SQLTableDataSet(table_name, credentials, load_args=None, save_args=None)[source]¶ SQLTableDataSetloads data from a SQL table and saves a pandas dataframe to a table. It usespandas.DataFrameinternally, so it supports all allowed pandas options onread_sql_tableandto_sqlmethods. However, it modifies the save parameters and stores the data with no index. This is designed to make load and save methods symmetric.Example:
from kedro.io import SQLTableDataSet import pandas as pd data = pd.DataFrame({'col1': [1, 2], 'col2': [4, 5], 'col3': [5, 6]}) table_name="table_a" credentials = { con: "postgresql://scott:tiger@localhost/test" } data_set = SQLTableDataSet(table_name=table_name, credentials=credentials) data_set.save(data) reloaded = data_set.load() assert data.equals(reloaded)
-
__init__(table_name, credentials, load_args=None, save_args=None)[source]¶ Creates a new
SQLTableDataSet.Parameters: - table_name (
str) – The table name to load or save data to. It overwrites name insave_argsandtable_nameparameters inload_args. - credentials (
Dict[str,Any]) – A dictionary with aSQLAlchemyconnection string. Users are supposed to provide the connection string ‘con’ through credentials. It overwrites con parameter inload_argsandsave_argsin case it is provided. - load_args (
Optional[Dict[str,Any]]) – Provided to underlying pandasread_sql_tablefunction along with the connection string. To find all supported arguments, see here: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_sql_table.html - save_args (
Optional[Dict[str,Any]]) – Provided to underlying pandasto_sqlfunction along with the connection string. To find all supported arguments, see here: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html It hasindex=Falsein the default parameters.
Raises: DataSetError– When eithertable_nameorconis empty.Return type: None- table_name (
Methods
__init__(table_name, credentials[, …])Creates a new SQLTableDataSet.exists()Checks whether a data set’s output already exists by calling the provided _exists() method. from_config(name, config[, load_version, …])Create a data set instance using the configuration provided. load()Loads data by delegation to the provided load method. save(data)Saves data by delegation to the provided save method. -