Create data assets

APPLIES TO: Azure CLI ml extension v2 (current) Python SDK azure-ai-ml v2 (current)

In this article, you learn how to create a data asset in Azure Machine Learning. By creating a data asset, you create a reference to the data source location, along with a copy of its metadata. Because the data remains in its existing location, you incur no extra storage cost, and don't risk the integrity of your data sources. You can create Data from Azure ML datastores, Azure Storage, public URLs, and local files.

Important

If you just want to access your data in an interactive session (for example, a Notebook) or a job, you are not required to create a data asset first. Creating a data asset would be an unnecessary step for you.

For more information about accessing your data in a notebook, please see Access data from Azure cloud storage for interactive development.

For more information about accessing your data - both local and cloud storage - in a job, please see Access data in a job.

Creating data assets are useful when you want to:

  • Share and reuse data with other members of your team so that they don't need to remember file locations in cloud storage.
  • Version the metadata such as location, description and tags.

Prerequisites

To create and work with data assets, you need:

Supported paths

When you create a data asset in Azure Machine Learning, you'll need to specify a path parameter that points to its location. Below is a table that shows the different data locations supported in Azure Machine Learning and examples for the path parameter:

Location Examples
A path on your local computer ./home/username/data/my_data
A path on a datastore azureml://datastores/<data_store_name>/paths/<path>
A path on a public http(s) server https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv
A path on Azure Storage wasbs://<containername>@<accountname>.blob.core.windows.net/<path_to_data>/
abfss://<file_system>@<account_name>.dfs.core.windows.net/<path>
adl://<accountname>.azuredatalakestore.net/<path_to_data>/
https://<account_name>.blob.core.windows.net/<container_name>/path

Note

When you create a data asset from a local path, it will be automatically uploaded to the default Azure Machine Learning datastore in the cloud.

Important

The studio only supports browsing of credential-less ADLS Gen 2 datastores.

Data asset types

  • [URIs](#Create a uri_folder data asset) - A Uniform Resource Identifier that is a reference to a storage location on your local computer or in the cloud that makes it easy to access data in your jobs. Azure Machine Learning distinguishes two types of URIs:uri_file and uri_folder.

  • [MLTable](#Create a mltable data asset) - MLTable helps you to abstract the schema definition for tabular data so it is more suitable for complex/changing schema or to be used in AutoML. If you just want to create a data asset for a job or you want to write your own parsing logic in Python you could use uri_file, uri_folder.

The ideal scenarios to use mltable are:

  • The schema of your data is complex and/or changes frequently.
  • You only need a subset of data (for example: a sample of rows or files, specific columns, etc.)
  • AutoML jobs requiring tabular data.

If your scenario does not fit the above then it is likely that URIs are a more suitable type.

Create a uri_folder data asset

Below shows you how to create a folder as an asset:

Create a YAML file (<file-name>.yml):

$schema: https://azuremlschemas.azureedge.net/latest/data.schema.json

# Supported paths include:
# local: ./<path>
# blob:  https://<account_name>.blob.core.windows.net/<container_name>/<path>
# ADLS gen2: abfss://<file_system>@<account_name>.dfs.core.windows.net/<path>/
# Datastore: azureml://datastores/<data_store_name>/paths/<path>
type: uri_folder
name: <name_of_data>
description: <description goes here>
path: <path>

Next, create the data asset using the CLI:

az ml data create -f <file-name>.yml

Create a uri_file data asset

Below shows you how to create a specific file as a data asset:

Sample YAML file <file-name>.yml for data in local path is as below:

$schema: https://azuremlschemas.azureedge.net/latest/data.schema.json

# Supported paths include:
# local: ./<path>/<file>
# blob:  https://<account_name>.blob.core.windows.net/<container_name>/<path>/<file>
# ADLS gen2: abfss://<file_system>@<account_name>.dfs.core.windows.net/<path>/<file>
# Datastore: azureml://datastores/<data_store_name>/paths/<path>/<file>

type: uri_file
name: <name>
description: <description>
path: <uri>
> az ml data create -f <file-name>.yml

Create a mltable data asset

mltable is a way to abstract the schema definition for tabular data to make it easier to share data assets (an overview can be found in MLTable). mltable supports tabular data coming from following sources:

  • Delimited files (CSV, TSV, TXT)
  • Parquet files
  • JSON Lines
  • Delta Lake

Find more details about what are the abilities we provide via mltable in reference-yaml-mltable.

In this section, we show you how to create a data asset when the type is a mltable.

The MLTable file

The MLTable file is a file that provides the specification of the data's schema so that the mltable engine can materialize the data into an in-memory object (Pandas/Dask/Spark).

Note

This file needs to be named exactly as MLTable.

An example MLTable file for delimited files is provided below:

type: mltable

paths:
  - pattern: ./*.txt
transformations:
  - read_delimited:
      delimiter: ,
      encoding: ascii
      header: all_files_same_headers

An example MLTable file for Delta Lake is provided below:

type: mltable

paths:
  - abfss://my_delta_files

transformations:
  - read_delta_lake:
      timestamp_as_of: '2022-08-26T00:00:00Z'
#timestamp_as_of: Timestamp to be specified for time-travel on the specific Delta Lake data.
#version_as_of: Version to be specified for time-travel on the specific Delta Lake data.

For more transformations available in mltable, please look into reference-yaml-mltable.

Important

We recommend co-locating the MLTable file with the underlying data in storage. For example:

├── my_data
│   ├── MLTable
│   ├── file_1.txt
.
.
.
│   ├── file_n.txt

Co-locating the MLTable with the data ensures a self-contained artifact where all that is needed is stored in that one folder (my_data); regardless of whether that folder is stored on your local drive or in your cloud store or on a public http server. You should not specify absolute paths in the MLTable file.

Create an MLTable artifact via Python SDK: from_*

If you would like to create an MLTable object in memory via Python SDK, you could use from_* methods. The from_* methods do not materialize the data, but rather stores it as a transformation in the MLTable definition.

For example you can use from_delta_lake() to create an in-memory MLTable artifact to read delta lake data from the path delta_table_path.

import mltable as mlt
mltable = from_delta_lake(delta_table_path, timestamp_as_of="2021-01-01T00:00:00Z")
df = mltable.to_pandas_dataframe()
print(df.to_string())

Please find more details about MLTable Python functions here.

In your Python code, you materialize the MLTable artifact into a Pandas dataframe using:

import mltable

tbl = mltable.load(uri="./my_data")
df = tbl.to_pandas_dataframe()

The uri parameter in mltable.load() should be a valid path to a local or cloud folder which contains a valid MLTable file.

Note

You will need the mltable library installed in your Environment (pip install mltable).

Below shows you how to create a mltable data asset. The path can be any of the supported path formats outlined above.

Create a YAML file (<file-name>.yml):

$schema: https://azuremlschemas.azureedge.net/latest/data.schema.json

# path must point to **folder** containing MLTable artifact (MLTable file + data
# Supported paths include:
# local: ./<path>
# blob:  https://<account_name>.blob.core.windows.net/<container_name>/<path>
# ADLS gen2: abfss://<file_system>@<account_name>.dfs.core.windows.net/<path>/
# Datastore: azureml://datastores/<data_store_name>/paths/<path>

type: mltable
name: <name_of_data>
description: <description goes here>
path: <path>

Note

The path points to the folder containing the MLTable artifact.

Next, create the data asset using the CLI:

az ml data create -f <file-name>.yml

Next steps