Skip to content

Commit

Permalink
modernize with pyugprade
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregg committed Aug 9, 2024
1 parent 614b866 commit d0351da
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dedupe/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def blocks(self, data):
con.execute("ROLLBACK")
con.close()

def score(self, blocks: Blocks) -> Generator[Scores, None, None]:
def score(self, blocks: Blocks) -> Generator[Scores]:
"""
Scores groups of pairs of records. Yields structured numpy arrays
representing pairs of records in the group and the associated
Expand Down
2 changes: 1 addition & 1 deletion dedupe/blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, predicates: Iterable[dedupe.predicates.Predicate]) -> None:

def __call__(
self, records: Iterable[Record], target: bool = False
) -> Generator[tuple[str, RecordID], None, None]:
) -> Generator[tuple[str, RecordID]]:
"""
Generate the predicates for records. Yields tuples of (predicate,
record_id).
Expand Down
8 changes: 2 additions & 6 deletions dedupe/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
logger = logging.getLogger(__name__)


def connected_components(
edgelist: Scores, max_components: int
) -> Generator[Scores, None, None]:
def connected_components(edgelist: Scores, max_components: int) -> Generator[Scores]:
if len(edgelist) == 0:
raise StopIteration()

Expand Down Expand Up @@ -51,9 +49,7 @@ def connected_components(
edgelist._mmap.close() # type: ignore


def _connected_components(
edgelist: Scores, max_components: int
) -> Generator[Scores, None, None]:
def _connected_components(edgelist: Scores, max_components: int) -> Generator[Scores]:
component_stops = union_find(edgelist)

start = 0
Expand Down
2 changes: 1 addition & 1 deletion dedupe/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def console_label(deduper: dedupe.api.ActiveMatching) -> None: # pragma: no cov

for record in record_pair:
for field in fields:
line = "{} : {}".format(field, record[field])
line = f"{field} : {record[field]}"
_print(line)
_print()
_print(f"{n_match}/10 positive, {n_distinct}/10 negative")
Expand Down
2 changes: 1 addition & 1 deletion dedupe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def scoreGazette(
featurizer: FeaturizerFunction,
classifier: Classifier,
num_cores: int = 1,
) -> Generator[Scores, None, None]:
) -> Generator[Scores]:
first, record_pairs = peek(record_pairs)
if first is None:
return # terminate iteration
Expand Down
2 changes: 1 addition & 1 deletion dedupe/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __len__(self) -> int:
@property
def _field_comparators(
self,
) -> Generator[tuple[str, Comparator, int, int], None, None]:
) -> Generator[tuple[str, Comparator, int, int]]:
start = 0
stop = 0
for var in self.field_variables:
Expand Down
8 changes: 4 additions & 4 deletions dedupe/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __iter__(self):
yield self

def __repr__(self) -> str:
return "{}: {}".format(self.type, self.__name__)
return f"{self.type}: {self.__name__}"

def __hash__(self) -> int:
try:
Expand Down Expand Up @@ -83,7 +83,7 @@ class SimplePredicate(Predicate):

def __init__(self, func: PredicateFunction, field: str):
self.func = func
self.__name__ = "({}, {})".format(func.__name__, field)
self.__name__ = f"({func.__name__}, {field})"
self.field = field

def __call__(self, record: RecordDict, **kwargs) -> frozenset[str]:
Expand All @@ -107,7 +107,7 @@ class ExistsPredicate(Predicate):
type = "ExistsPredicate"

def __init__(self, field: str):
self.__name__ = "(Exists, {})".format(field)
self.__name__ = f"(Exists, {field})"
self.field = field

@staticmethod
Expand All @@ -129,7 +129,7 @@ class IndexPredicate(Predicate):
_cache: dict[Any, frozenset[str]]

def __init__(self, threshold: float, field: str):
self.__name__ = "({}, {})".format(threshold, field)
self.__name__ = f"({threshold}, {field})"
self.field = field
self.threshold = threshold
self.index = None
Expand Down
4 changes: 2 additions & 2 deletions dedupe/variables/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DerivedType(Variable):
type = "Derived"

def __init__(self, name: str, var_type: str, **kwargs):
self.name = "({}: {})".format(str(name), str(var_type))
self.name = f"({str(name)}: {str(var_type)})"
super().__init__(**kwargs)


Expand All @@ -59,7 +59,7 @@ def __init__(self, field: str, name: str | None = None, has_missing: bool = Fals
self.field = field

if name is None:
self.name = "({}: {})".format(self.field, self.type)
self.name = f"({self.field}: {self.type})"
else:
self.name = name

Expand Down

0 comments on commit d0351da

Please sign in to comment.