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

OrderColumn Differences #295

Merged
merged 4 commits into from
Jun 28, 2021
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
20 changes: 20 additions & 0 deletions dataprofiler/profilers/order_column_profile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import BaseColumnProfiler
from . import utils
from .profiler_options import OrderOptions


Expand Down Expand Up @@ -237,6 +238,25 @@ def profile(self):
"""
return dict(order=self.order, times=self.times)

def diff(self, other_profile, options=None):
"""
Generates the differences between the orders of two OrderColumns

:return: Dict containing the differences between orders in their
appropriate output formats
:rtype: dict
"""
cls = self.__class__
if not isinstance(other_profile, cls):
raise TypeError("Unsupported operand type(s) for diff: '{}' "
"and '{}'".format(cls.__name__,
other_profile.__class__.__name__))

differences = {
"order": utils.find_diff_of_strings(self.order, other_profile.order)
}
return differences

@BaseColumnProfiler._timeit(name="order")
def _get_data_order(self, df_series):
"""
Expand Down
22 changes: 22 additions & 0 deletions dataprofiler/tests/profilers/test_order_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,25 @@ def test_order_column_with_wrong_options(self):
"OrderColumn parameter 'options' must be of"
" type OrderOptions."):
profiler = OrderColumn("Order", options="wrong_data_type")

def test_diff(self):
data = [1, 2, 3, 4, 5, 6]
df = pd.Series(data).apply(str)
profiler = OrderColumn("placeholder_name")
profiler.update(df)

data2 = [7, 8, 9, 10]
df2 = pd.Series(data2).apply(str)
profiler2 = OrderColumn("placeholder_name")
profiler2.update(df2)

diff = profiler.diff(profiler2)
self.assertEqual("unchanged", diff["order"])

data3 = [4, 2, 3, 1, 5]
df3 = pd.Series(data3).apply(str)
profiler3 = OrderColumn("placeholder_name")
profiler3.update(df3)

diff = profiler.diff(profiler3)
self.assertEqual(["ascending", "random"], diff["order"])