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 bug with null replication metrics when row is all null #706

Merged
merged 6 commits into from
Nov 8, 2022
Merged
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: 5 additions & 1 deletion dataprofiler/profilers/profile_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,11 @@ def _update_null_replication_metrics(self, clean_samples: Dict) -> None:
# Partition data based on whether target column value is null or not
# Calculate sum, mean of each partition without including current column
# in calculation
sum_null = data.iloc[null_indices, data.columns != col_id].sum().to_numpy()
sum_null = (
data.loc[data.index.intersection(null_indices), data.columns != col_id]
.sum()
.to_numpy()
)
Comment on lines +2290 to +2294
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code does not error anymore if the entire DataFrame is null.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is much cleaner!

Copy link
Contributor

Choose a reason for hiding this comment

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

beautiful!


# Add old sum_null if exists
if col_id in self._null_replication_metrics:
Expand Down
15 changes: 15 additions & 0 deletions dataprofiler/tests/profilers/test_profile_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,6 +2081,21 @@ def test_null_replication_metrics_calculation(self):
np.testing.assert_array_almost_equal([[np.nan], [18]], column["class_sum"])
np.testing.assert_array_almost_equal([[np.nan], [9]], column["class_mean"])

# Test with all null in a row
data_4 = pd.DataFrame(
[[10, 20], [9999999, 9999999], [30, 9999999], [9999999, 9999999]]
)

profiler = dp.StructuredProfiler(data_4, options=profile_options)
report = profiler.report()

self.assertTrue("null_replication_metrics" in report["data_stats"][0])
column = report["data_stats"][0]["null_replication_metrics"]

np.testing.assert_array_almost_equal([0.5, 0.5], column["class_prior"])
np.testing.assert_array_almost_equal([[20], [0]], column["class_sum"])
np.testing.assert_array_almost_equal([[10], [0]], column["class_mean"])

def test_column_level_invalid_values(self):
data = pd.DataFrame([[1, 1], [9999999, 2], [3, 3]])

Expand Down