load_example_data() Function | Teradata Package for Python - 17.00 - load_example_data() Function - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Release Date
November 2021
Content Type
User Guide
Publication ID
B700-4006-070K
Language
English (United States)

The load_example_data() is a helper function that loads the sample datasets.

Teradata Package for Python offers various APIs and each API provides some examples. To test these examples, users need the sample datasets loaded in Vantage.

The load_example_data() function can only be used in a restricted way. Function arguments only accept predetermined values as shown in the given examples in this User Guide and the Teradata Package for Python Function Reference.

  • function_name

    This required argument contains the prefix name of the example JSON file to be used to load data.

    You must specify the function_name values as specified in the example sections of corresponding teradataml APIs. If any other string is passed as prefix input, an error will be raised as 'prefix_str_example.json' file not found. This *_example.json file contains the schema information for the tables that can be loaded using this JSON file.
  • table_name

    This required argument specifies the name(s) of the table to be created in the database.

    Table names provided here must have an equivalent datafile (CSV) present at teradataml/data. Schema information for the same must also be present in <function_name>_example.json as shown in 'function_name' argument description.
  • The function creates a new table in Vantage with the name specified in the table_name argument. You must manually drop the table if required.
  • If a table with the name provided for table_name argument already exists, this function skips creation and loading of the dataset.
  • Database used for loading table depends on the following conditions:
    • If the configuration option temp_table_database is set, then the tables are loaded in the database specified in this option.
    • If the configuration option temp_table_database is not set and the temp_database_name argument is used while creating context, then the tables are loaded in the database specified in the temp_database_name argument.
    • If none of them are specified, then the tables are created in the connecting users' default database or the connecting database.

Example 1: When connection is created without temp_database_name, table is loaded in users' default database

>>> from teradataml import *
>>> con = create_context(host = 'tdhost', username='tduser', password = 'tdpassword')
>>> load_example_data("pack", "ville_temperature")
# Create a teradataml DataFrame.
>>> df = DataFrame("ville_temperature")

Example 2: When connection is created with temp_database_name, table is loaded in that database

This examples shows when connection is created with the temp_database_name argument, then tables are loaded in the database specified in the temp_database_name argument.

This example also demonstrates loading multiple tables in a single function call.

>>> con = create_context(host = 'tdhost', username='tduser', password = 'tdpassword', temp_database_name = "temp_db")
>>> load_example_data("GLM", ["admissions_train", "housing_train"])
# Create teradataml DataFrames.
>>> admission_train = DataFrame(in_schema("temp_db", "admissions_train"))
>>> housing_train = DataFrame(in_schema("temp_db", "housing_train"))

Example 3: When connection is created with temp_database_name and the configuration option temp_table_database is set

This example shows when connection is created with temp_database_name and the configuration option temp_table_database is also specified, the table is created in the database specified in the configuration option temp_table_database.

>>> from teradataml import *
>>> con = create_context(host = 'tdhost', username='tduser', password = 'tdpassword', temp_database_name = "temp_db")
>>> configure.temp_table_database = "temp_db1"
>>> load_example_data("pack", "ville_temperature")
# Create a teradataml DataFrame.
>>> df = DataFrame(in_schema("temp_db1", "ville_temperature"))