handle datasets with one column only

This commit is contained in:
evilchili 2024-02-17 16:57:51 -08:00
parent 4922eeb3e6
commit 3a540ff597
2 changed files with 14 additions and 0 deletions

View File

@ -124,6 +124,7 @@ class DataSource:
# If there is no data for the specified option, stop now. # If there is no data for the specified option, stop now.
flattened = [] flattened = []
if not self.data[option]: if not self.data[option]:
return [option]
raise ValueError(f"There is no data for '{option}' in your data source.") raise ValueError(f"There is no data for '{option}' in your data source.")
if hasattr(self.data[option], 'keys'): if hasattr(self.data[option], 'keys'):

View File

@ -56,6 +56,19 @@ def test_zero_frequency():
assert 'Option 1' not in val assert 'Option 1' not in val
def test_one_column_only():
fixture = StringIO(f"""
{fixture_metadata}
Option 1:
Option 2:
Option 3:
""")
ds = datasources.DataSource(fixture)
vals = ds.random_values(count=10)
assert len(vals) == 10
assert len(vals[0]) == 1
def test_distribution_accuracy_to_one_decimal_place(): def test_distribution_accuracy_to_one_decimal_place():
fixture = StringIO(fixture_metadata + fixture_source) fixture = StringIO(fixture_metadata + fixture_source)
ds = datasources.DataSource(fixture) ds = datasources.DataSource(fixture)