Skip to content

Commit

Permalink
Allow user to have non-str in pandas passed to Labeler (capitalone#343)
Browse files Browse the repository at this point in the history
* fix: allow user to have non-str in pandas passed to Labeler

* fix: naming to be sample as not necessarily string
  • Loading branch information
JGSweets authored Jul 19, 2021
1 parent ad3b919 commit 7127737
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dataprofiler/labelers/data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,11 +1434,11 @@ def convert_to_structured_analysis(self, sentences, results, label_mapping,
if 'conf' in results:
confs_out = np.zeros((len(results['pred']), num_labels))

for i, label_sentences in enumerate(zip(results['pred'], sentences)):
column_labels, sentence = label_sentences
for i, label_samples in enumerate(zip(results['pred'], sentences)):
column_labels, sample = label_samples

# get count of all labels in prediction
column_label_counter = Counter(column_labels[:len(sentence)])
column_label_counter = Counter(column_labels[:len(str(sample))])
column_label_counter.pop(ignore_value, None)
modes = [entity_id for entity_id, count in
column_label_counter.most_common() if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def test_fit_with_default_model(self):
# validate epoch id
self.assertEqual(2, default.model._epoch_id)

def test_labeling_mixed_df(self):
labeler = dp.labelers.StructuredDataLabeler()

# test int, float, str, dict
data = pd.DataFrame([1, 1.1, 'string', {'random': 3}])
predictions = labeler.predict(data)
self.assertEqual(4, len(predictions['pred']))

def test_data_labeler_change_labels(self):
"""test changing labels of data labeler with fitting data"""
# constructing default StructuredDataLabeler()
Expand Down Expand Up @@ -391,5 +399,6 @@ def test_warning_tf_multiple_dp_with_update(self):

profile1.update_profile(data)


if __name__ == '__main__':
unittest.main()

0 comments on commit 7127737

Please sign in to comment.