Implementation:Sdv dev SDV Metadata Upgrader
| Knowledge Sources | |
|---|---|
| Domains | Metadata, Migration |
| Last Updated | 2026-02-14 19:00 GMT |
Overview
Concrete tool for converting legacy SDV metadata format to the current metadata schema provided by the SDV library.
Description
The sdv.metadata.metadata_upgrader module provides the convert_metadata function and a suite of internal helpers that transform old-format SDV metadata dictionaries (pre-v1.0 style with fields, type/subtype, and old constraint names) into the new-format metadata (with columns, sdtype, and updated constraint class names). It handles upgrading columns, keys, and constraints including GreaterThan to Inequality/ScalarInequality, Between to Range/ScalarRange, UniqueCombinations to FixedCombinations, and Positive/Negative to per-column ScalarInequality constraints.
Usage
Use convert_metadata when migrating from SDV versions prior to 1.0 that used the old metadata format. Pass in the old metadata dict and receive a new-format dict compatible with the current Metadata API.
Code Reference
Source Location
- Repository: Sdv_dev_SDV
- File: sdv/metadata/metadata_upgrader.py
- Lines: 1-312
Signature
def convert_metadata(old_metadata: dict) -> dict:
"""Convert old metadata to the new metadata format.
Args:
old_metadata (dict):
A dict version of the old metadata.
Returns:
An equivalent dict in the new metadata format.
"""
Import
from sdv.metadata.metadata_upgrader import convert_metadata
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| old_metadata | dict | Yes | Old-format metadata dict with 'fields', 'primary_key', and optional 'constraints' |
Outputs
| Name | Type | Description |
|---|---|---|
| new_metadata | dict | New-format metadata with 'columns' (sdtype-based), 'primary_key', and 'alternate_keys' |
Usage Examples
Basic Metadata Conversion
from sdv.metadata.metadata_upgrader import convert_metadata
old_metadata = {
'fields': {
'user_id': {'type': 'id', 'subtype': 'integer'},
'name': {'type': 'categorical'},
'age': {'type': 'numerical', 'subtype': 'integer'},
'signup_date': {'type': 'datetime', 'format': '%Y-%m-%d'},
},
'primary_key': 'user_id',
}
new_metadata = convert_metadata(old_metadata)
# Result:
# {
# 'columns': {
# 'user_id': {'sdtype': 'id', 'regex_format': '\\d{30}'},
# 'name': {'sdtype': 'categorical'},
# 'age': {'sdtype': 'numerical', 'computer_representation': 'Int64'},
# 'signup_date': {'sdtype': 'datetime', 'datetime_format': '%Y-%m-%d'},
# },
# 'primary_key': 'user_id',
# }