Skip to content

Commit

Permalink
FloatColumn: enable pop when remove_disabled_flag set to True (#493)
Browse files Browse the repository at this point in the history
* update float to remove_disabled_keys

* fix docstring
  • Loading branch information
taylorfturner authored Jun 24, 2022
1 parent 98ef862 commit bd8e91a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dataprofiler/profilers/float_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ def diff(self, other_profile, options=None):
differences["precision"] = precision_diff
return differences

def report(self, remove_disabled_flag=False):
"""Report on profile attribute of the class and pop value
from self.profile if key not in self.__calculations
"""
calcs_dict_keys = self._FloatColumn__calculations.keys()
profile = self.profile

if remove_disabled_flag:
profile_keys = list(profile.keys())
for profile_key in profile_keys:
if profile_key == 'precision':
if 'precision' in calcs_dict_keys:
continue
profile.pop(profile_key)

return profile

@property
def profile(self):
"""
Expand Down
31 changes: 31 additions & 0 deletions dataprofiler/tests/profilers/test_float_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,37 @@ def test_profile(self):
'num_zeros': 2.0,})
self.assertEqual(expected, profiler.profile['times'])

def test_report(self):
"""Test report method in FloatColumn class under three (3) scenarios.
First, test under scenario of disabling the entire
precision dictionary. Second, test with no options and
`remove_disabled_flag`=True. Finally, test no options and default
`remove_disabled_flag`.
"""
data = [1.1, 2.2, 3.3, 4.4]
df = pd.Series(data).apply(str)

# With FloatOptions and remove_disabled_flag == True
options = FloatOptions()
options.precision.is_enabled = False

profiler = FloatColumn(df.name, options)
report = profiler.report(remove_disabled_flag=True)
report_keys = list(report.keys())
self.assertNotIn('precision', report_keys)

# w/o FloatOptions and remove_disabled_flag == True
profiler = FloatColumn(df.name)
report = profiler.report(remove_disabled_flag=True)
report_keys = list(report.keys())
self.assertIn('precision', report_keys)

# w/o FloatOptions and remove_disabled_flag default
profiler = FloatColumn(df.name)
report = profiler.report()
report_keys = list(report.keys())
self.assertIn('precision', report_keys)

def test_option_precision(self):
data = [1.1, 2.2, 3.3, 4.4]
df = pd.Series(data).apply(str)
Expand Down

0 comments on commit bd8e91a

Please sign in to comment.