Skip to content

Commit 4fea33a

Browse files
committed
make ints into bools
1 parent caa0209 commit 4fea33a

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

sdmetrics/reports/single_table/_properties/column_pair_trends.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ def _generate_details(
392392
'Meets Threshold?': meets_threshold,
393393
'Error': error_messages,
394394
})
395+
result['Meets Threshold?'] = result['Meets Threshold?'].astype('boolean')
395396

396397
if result['Error'].isna().all():
397398
result = result.drop('Error', axis=1)

tests/integration/reports/multi_table/test_quality_report.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_multi_table_quality_report():
142142
'Real Correlation': [np.nan],
143143
'Synthetic Correlation': [np.nan],
144144
'Real Association': [np.nan],
145-
'Meets Threshold?': [True],
145+
'Meets Threshold?': pd.Series([True], dtype='boolean'),
146146
})
147147
pd.testing.assert_frame_equal(details[1], expected_df_1)
148148

@@ -176,7 +176,7 @@ def test_multi_table_quality_report():
176176
'Real Correlation': [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
177177
'Synthetic Correlation': [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
178178
'Real Association': [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
179-
'Meets Threshold?': [True, True, True, True, True, True],
179+
'Meets Threshold?': pd.Series([True, True, True, True, True, True], dtype='boolean'),
180180
})
181181
pd.testing.assert_frame_equal(details[3], expected_df_3)
182182
pd.testing.assert_frame_equal(details[7], expected_df_3)
@@ -205,7 +205,7 @@ def test_multi_table_quality_report():
205205
'Real Correlation': [np.nan, 0.946664, 0.966247, 0.862622],
206206
'Synthetic Correlation': [np.nan, 0.926925, 0.936853, 0.798384],
207207
'Real Association': [np.nan, np.nan, np.nan, np.nan],
208-
'Meets Threshold?': [True, True, True, True],
208+
'Meets Threshold?': pd.Series([True, True, True, True], dtype='boolean'),
209209
})
210210
pd.testing.assert_frame_equal(details[5], expected_df_4)
211211

tests/integration/reports/single_table/_properties/test_column_pair_trends.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_get_score(self):
6161
'Real Correlation': [0.04735340044317632, np.nan, np.nan, np.nan, np.nan, np.nan],
6262
'Synthetic Correlation': [-0.11506297326956302, np.nan, np.nan, np.nan, np.nan, np.nan],
6363
'Real Association': [np.nan] * 6,
64-
'Meets Threshold?': [True] * 6,
64+
'Meets Threshold?': pd.Series([True] * 6, dtype='boolean'),
6565
}
6666
expected_details = pd.DataFrame(expected_details_dict)
6767
pd.testing.assert_frame_equal(column_pair_trends.details, expected_details)
@@ -151,7 +151,7 @@ def test_only_categorical_columns(self):
151151
'Real Correlation': [np.nan] * 6,
152152
'Synthetic Correlation': [np.nan] * 6,
153153
'Real Association': [np.nan] * 6,
154-
'Meets Threshold?': [True] * 6,
154+
'Meets Threshold?': pd.Series([True] * 6, dtype='boolean'),
155155
}
156156
expected_details = pd.DataFrame(expected_details_dict)
157157
pd.testing.assert_frame_equal(column_pair_trends.details, expected_details)
@@ -187,7 +187,7 @@ def test_real_association_threshold_filters_pairs(self):
187187
'Real Correlation': [np.nan, np.nan, np.nan],
188188
'Synthetic Correlation': [np.nan, np.nan, np.nan],
189189
'Real Association': [0.0, 1.0, 0.0],
190-
'Meets Threshold?': [False, True, False],
190+
'Meets Threshold?': pd.Series([False, True, False], dtype='boolean'),
191191
})
192192
pd.testing.assert_frame_equal(column_pair_trends.details, expected_details)
193193
assert score == 1.0

tests/integration/reports/single_table/test_quality_report.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def test_report_end_to_end(self):
146146
np.nan,
147147
],
148148
'Real Association': [np.nan] * 6,
149-
'Meets Threshold?': [True] * 6,
149+
'Meets Threshold?': pd.Series([True] * 6, dtype='boolean'),
150150
}
151151
expected_details_column_shapes = pd.DataFrame(expected_details_column_shapes_dict)
152152
expected_details_cpt = pd.DataFrame(expected_details_cpt__dict)
@@ -314,7 +314,7 @@ def test_quality_report_with_object_datetimes(self):
314314
np.nan,
315315
],
316316
'Real Association': [np.nan] * 6,
317-
'Meets Threshold?': [True] * 6,
317+
'Meets Threshold?': pd.Series([True] * 6, dtype='boolean'),
318318
}
319319
expected_details_column_shapes = pd.DataFrame(expected_details_column_shapes_dict)
320320
expected_details_cpt = pd.DataFrame(expected_details_cpt__dict)
@@ -394,7 +394,9 @@ def test_report_end_to_end_with_errors(self):
394394
'Real Correlation': [np.nan] * 6,
395395
'Synthetic Correlation': [np.nan] * 6,
396396
'Real Association': [np.nan] * 6,
397-
'Meets Threshold?': [np.nan, True, True, np.nan, np.nan, True],
397+
'Meets Threshold?': pd.Series(
398+
[np.nan, True, True, np.nan, np.nan, True], dtype='boolean'
399+
),
398400
'Error': [
399401
'AttributeError', # This can be either ValueError or AttributeError
400402
None,
@@ -417,6 +419,27 @@ def test_report_end_to_end_with_errors(self):
417419
pd.testing.assert_frame_equal(col_pair_report[1:], expected_details_cpt[1:])
418420
assert report.get_score() == 0.8204378797402054
419421

422+
def test_meets_threshold_column_has_boolean_dtype_with_errors(self):
423+
"""Test that 'Meets Threshold?' column contains booleans when errors occur."""
424+
# Setup
425+
real_data, synthetic_data, metadata = load_demo(modality='single_table')
426+
real_data.loc[2, 'second_perc'] = 'a' # Corrupt data to trigger errors
427+
428+
# Run
429+
report = QualityReport()
430+
report.generate(real_data, synthetic_data, metadata, verbose=False)
431+
details = report.get_details('Column Pair Trends')
432+
433+
# Assert
434+
meets_threshold_col = details['Meets Threshold?']
435+
assert meets_threshold_col.dtype == 'boolean'
436+
437+
# Ensure non-NA values are actual booleans, not integers
438+
non_na_values = meets_threshold_col.dropna()
439+
assert len(non_na_values) > 0
440+
for val in non_na_values:
441+
assert isinstance(val, np.bool_)
442+
420443
def test_report_with_column_nan(self):
421444
"""Test the report with column full of NaNs."""
422445
# Setup
@@ -538,7 +561,9 @@ def test_report_with_column_nan(self):
538561
np.nan,
539562
],
540563
'Real Association': [np.nan] * 10,
541-
'Meets Threshold?': [True, True, True, np.nan, True, True, np.nan, True, True, True],
564+
'Meets Threshold?': pd.array(
565+
[True, True, True, pd.NA, True, True, pd.NA, True, True, True], dtype='boolean'
566+
),
542567
'Error': [
543568
None,
544569
None,

tests/unit/reports/single_table/_properties/test_column_pair_trends.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def test__generate_details_real_correlation_threshold(self, correlation_compute_
496496
'Real Correlation': [0.2],
497497
'Synthetic Correlation': [0.1],
498498
'Real Association': [np.nan],
499-
'Meets Threshold?': [False],
499+
'Meets Threshold?': pd.Series([False], dtype='boolean'),
500500
})
501501
pd.testing.assert_frame_equal(details, expected_details)
502502
correlation_compute_mock.assert_called_once()
@@ -531,7 +531,7 @@ def test__generate_details_real_association_threshold(self, contingency_compute_
531531
'Real Correlation': [np.nan],
532532
'Synthetic Correlation': [np.nan],
533533
'Real Association': [0.2],
534-
'Meets Threshold?': [False],
534+
'Meets Threshold?': pd.Series([False], dtype='boolean'),
535535
})
536536
pd.testing.assert_frame_equal(details, expected_details)
537537
_, contingency_kwargs = contingency_compute_mock.call_args
@@ -641,7 +641,7 @@ def test_get_visualization_layout_alignment(self):
641641
'Real Correlation': [0.5],
642642
'Synthetic Correlation': [0.6],
643643
'Real Association': [0.2],
644-
'Meets Threshold?': [True],
644+
'Meets Threshold?': pd.Series([True], dtype='boolean'),
645645
})
646646

647647
# Run

0 commit comments

Comments
 (0)