Skip to content

Commit

Permalink
fix exists variables, closes #1196
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregg committed Jun 28, 2024
1 parent 7d2c79b commit aca1e3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 3 additions & 4 deletions dedupe/variables/exists.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
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] = []

def __init__(self, field: str, **kwargs):
super().__init__(field, **kwargs)
super().__init__(field, *kwargs)

self.cat_comparator = CategoricalComparator([0, 1])

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 aca1e3f

Please sign in to comment.