Skip to content

Commit

Permalink
add pad argument
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann authored Oct 9, 2023
1 parent 0de194f commit 94beb1e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

### v0.23.0
#### Changed
- added keyword argument `pad` to Hamming distance. This controls whether sequences of different
length should be padded or lead to a `ValueError`

### v0.22.0
#### Changed
- add support for Python 3.12
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Max Bachmann'

# The full version, including alpha/beta/rc tags
release = '0.22.0'
release = '0.23.0'

# -- General configuration ---------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

setup(
name="Levenshtein",
version="0.22.0",
version="0.23.0",
url="https://github.com/maxbachmann/Levenshtein",
author="Max Bachmann",
install_requires=["rapidfuzz >= 2.3.0, < 4.0.0"],
install_requires=["rapidfuzz >= 3.1.0, < 4.0.0"],
author_email="[email protected]",
description="Python extension for computing string edit distances and similarities.",
long_description=readme,
Expand Down
10 changes: 7 additions & 3 deletions src/Levenshtein/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

__author__: str = "Max Bachmann"
__license__: str = "GPL"
__version__: str = "0.22.0"
__version__: str = "0.23.0"

import rapidfuzz.distance.Levenshtein as _Levenshtein
import rapidfuzz.distance.Indel as _Indel
Expand Down Expand Up @@ -166,7 +166,7 @@ def ratio(s1, s2, *, processor=None, score_cutoff=None):
)


def hamming(s1, s2, *, processor=None, score_cutoff=None):
def hamming(s1, s2, *, pad=True, processor=None, score_cutoff=None):
"""
Calculates the Hamming distance between two strings.
The hamming distance is defined as the number of positions
Expand All @@ -179,6 +179,10 @@ def hamming(s1, s2, *, processor=None, score_cutoff=None):
First string to compare.
s2 : Sequence[Hashable]
Second string to compare.
pad : bool, optional
should strings be padded if there is a length difference.
If pad is False and strings have a different length
a ValueError is thrown instead. Default is True.
processor: callable, optional
Optional callable that is used to preprocess the strings before
comparing them. Default is None, which deactivates this behaviour.
Expand All @@ -198,7 +202,7 @@ def hamming(s1, s2, *, processor=None, score_cutoff=None):
ValueError
If s1 and s2 have a different length
"""
return _Hamming.distance(s1, s2, processor=processor, score_cutoff=score_cutoff)
return _Hamming.distance(s1, s2, pad=pad, processor=processor, score_cutoff=score_cutoff)


def jaro(s1, s2, *, processor=None, score_cutoff=None) -> float:
Expand Down

0 comments on commit 94beb1e

Please sign in to comment.