Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix column_name and null generation #337

Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions synthetic_data/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _generate_uncorrelated_column_data(self, num_samples):
col_ = copy.deepcopy(col)

generator_name = col_.get("data_type", None)

column_header = col_.get("column_name", None)
if not generator_name:
logging.warning(
f"Generator of type {generator_name} is not implemented."
Expand Down Expand Up @@ -178,7 +178,7 @@ def _generate_uncorrelated_column_data(self, num_samples):
else:
dataset.append(generated_data)

column_names.append(generator_name)
column_names.append(column_header)

return self.convert_data_to_df(dataset, column_names=column_names)

Expand Down
35 changes: 32 additions & 3 deletions tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,23 @@ def test_synthesize_uncorrelated_output(self):
np.testing.assert_array_equal(
actual_synthetic_data.columns.values,
np.array(
["datetime", "categorical", "int", "string", "float"], dtype="object"
[
"datetime",
"host",
"src",
"proto",
"srcport",
"destport",
"srcip",
"locale",
"localeabbr",
"postalcode",
"latitude",
"longitude",
"comment",
"int_col",
],
dtype="object",
),
)

Expand Down Expand Up @@ -308,6 +324,7 @@ def test_get_ordered_column_integration(self, mock_report, mock_warning):
"data_stats": [
{
"data_type": "int",
"column_name": "test_column_1",
"order": "ascending",
"statistics": {
"min": 1.0,
Expand All @@ -316,6 +333,7 @@ def test_get_ordered_column_integration(self, mock_report, mock_warning):
},
{
"data_type": "string",
"column_name": "test_column_2",
"categorical": False,
"order": "ascending",
"statistics": {
Expand All @@ -326,6 +344,7 @@ def test_get_ordered_column_integration(self, mock_report, mock_warning):
},
{
"data_type": "string",
"column_name": "test_column_3",
"categorical": True,
"order": "ascending",
"statistics": {
Expand All @@ -342,11 +361,13 @@ def test_get_ordered_column_integration(self, mock_report, mock_warning):
},
{
"data_type": "float",
"column_name": "test_column_4",
"order": "ascending",
"statistics": {"min": 2.11234, "max": 8.0, "precision": {"max": 6}},
},
{
"data_type": "datetime",
"column_name": "test_column_5",
"order": "ascending",
"statistics": {
"format": ["%Y-%m-%d"],
Expand Down Expand Up @@ -384,9 +405,17 @@ def test_get_ordered_column_integration(self, mock_report, mock_warning):
[4, "wqfed", "yellow", 7.775666, "2026-02-04"],
[4, "wsde", "yellow", 7.818521, "2027-06-13"],
]
categories = ["int", "string", "categorical", "float", "datetime"]
expected_column_names = [
"test_column_1",
"test_column_2",
"test_column_3",
"test_column_4",
"test_column_5",
]

expected_data = [dict(zip(categories, item)) for item in expected_array]
expected_data = [
dict(zip(expected_column_names, item)) for item in expected_array
]
expected_df = pd.DataFrame(expected_data)

actual_df = generator.synthesize(20)
Expand Down