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

Add diff for FloatColumn #300

Merged
merged 4 commits into from
Jun 30, 2021
Merged
Changes from 1 commit
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
42 changes: 42 additions & 0 deletions dataprofiler/tests/profilers/test_float_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,3 +1299,45 @@ def test_insufficient_counts(self):
# to make sure NO warnings were thrown since we have
# a sufficient match count.
self.assertEqual(0, len(w))

def test_diff(self):
data = [2.5, 12.5, 'not a float', 5, 'not a float']
df = pd.Series(data).apply(str)
profiler1 = FloatColumn(df.name)
profiler1.update(df)

data = [1, 15, 0.5, 0]
df = pd.Series(data).apply(str)
profiler2 = FloatColumn(df.name)
profiler2.update(df)

# Assert the difference report is correct
diff = profiler1.diff(profiler2)

expected_diff = {
'max': -2.5,
'mean': 2.5416667,
'min': 2.5,
'stddev': -2.0573202,
'sum': 3.5,
'variance': -25.6458333
}
expected_mean = expected_diff.pop("mean")
expected_std = expected_diff.pop("stddev")
expected_var = expected_diff.pop('variance')

mean = diff.pop("mean")
std = diff.pop("stddev")
var = diff.pop("variance")

self.assertDictEqual(expected_diff, diff)
self.assertAlmostEqual(expected_mean, mean)
self.assertAlmostEqual(expected_std, std)
self.assertAlmostEqual(expected_var, var)

# Assert type error is properly called
with self.assertRaises(TypeError) as exc:
profiler1.diff("Inproper input")
self.assertEqual(str(exc.exception),
"Unsupported operand type(s) for diff: 'FloatColumn' and"
" 'str'")