Skip to content

Commit

Permalink
Merge pull request #1 from ArVar/fix-exists
Browse files Browse the repository at this point in the history
Fix exists
  • Loading branch information
ArVar authored Jul 1, 2024
2 parents 3b4ceaa + 86086c6 commit a7258f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dedupe/variables/exists.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from categorical import CategoricalComparator

from dedupe._typing import PredicateFunction
from dedupe.variables.base import DerivedType
from dedupe.variables.categorical_type import CategoricalType
from dedupe.variables.base import DerivedType, FieldType


class ExistsType(CategoricalType):

class ExistsType(FieldType):
type = "Exists"
_predicate_functions: list[PredicateFunction] = []

Expand All @@ -30,6 +30,9 @@ def comparator(self, field_1: Any, field_2: Any) -> list[int]:
return self.cat_comparator(0, 1)
else:
return self.cat_comparator(0, 0)

def __len__(self) -> int:
return len(self.higher_vars)

# This flag tells fieldDistances in dedupe.core to pass
# missing values (None) into the comparator
Expand Down
13 changes: 13 additions & 0 deletions tests/test_exists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest

import numpy

from dedupe.variables.exists import ExistsType


class TestExists(unittest.TestCase):
def test_comparator(self):
var = ExistsType("foo")
assert numpy.array_equal(var.comparator(None, None), [0, 0])
assert numpy.array_equal(var.comparator(1, 1), [1, 0])
assert numpy.array_equal(var.comparator(1, 0), [0, 1])

0 comments on commit a7258f2

Please sign in to comment.