Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdv/datasets/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ def is_direct_json_under_prefix(key):
raw = _get_data_from_bucket(key, bucket=bucket, client=client)
metadict = json.loads(raw)
if isinstance(metadict, dict) and metadict.get('METADATA_SPEC_VERSION') == version:
if version != 'V2':
warnings.warn(
'An updated metadata V2 is not available for this dataset so the V1 '
'metadata was returned.\nYou should be able to model and sample with '
'the V1 metadata, but please report this issue to the DataCebo.'
)
return raw

except Exception:
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/datasets/test_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ def test_download_demo_adventure_works_raises_warning(preprocess_mock):
download_demo(modality='multi_table', dataset_name='adventure-works')


def test_download_demo_raise_warning_v2_metadata():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going to happen to this test when we update the demo datasets to have V2 metadata?

"""Test that a warning is raised if the V2 metadata is not available."""
# Setup
expected_warning = re.escape(
'An updated metadata V2 is not available for this dataset so the V1 '
'metadata was returned.\nYou should be able to model and sample with'
' the V1 metadata, but please report this issue to the DataCebo.'
)

# Run and Assert
with pytest.warns(UserWarning, match=expected_warning):
download_demo(modality='single_table', dataset_name='fake_hotel_guests')


def test_save_resource(tmp_path):
"""Test saving an arbitary demo resource."""
# Setup
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/datasets/test_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ def test__get_first_v2_metadata_bytes_falls_back_to_v1(mock_get):
v2 = json.dumps({'METADATA_SPEC_VERSION': 'V1'}).encode()
bad = b'not-json'
v1 = json.dumps({'METADATA_SPEC_VERSION': 'V1'}).encode()
expected_warning = re.escape(
'An updated metadata V2 is not available for this dataset so the V1 '
'metadata was returned.\nYou should be able to model and sample with'
' the V1 metadata, but please report this issue to the DataCebo.'
)

def side_effect(key, bucket, client):
return {
Expand All @@ -433,9 +438,10 @@ def side_effect(key, bucket, client):
]

# Run
got = _get_first_v2_metadata_bytes(
contents, 'single_table/dataset/', bucket='test_bucket', client=None
)
with pytest.warns(UserWarning, match=expected_warning):
got = _get_first_v2_metadata_bytes(
contents, 'single_table/dataset/', bucket='test_bucket', client=None
)

# Assert
assert got == v1
Expand Down