Skip to content

Commit 94beb1e

Browse files
authored
add pad argument
1 parent 0de194f commit 94beb1e

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Changelog
22

3+
### v0.23.0
4+
#### Changed
5+
- added keyword argument `pad` to Hamming distance. This controls whether sequences of different
6+
length should be padded or lead to a `ValueError`
7+
38
### v0.22.0
49
#### Changed
510
- add support for Python 3.12

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Max Bachmann'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '0.22.0'
25+
release = '0.23.0'
2626

2727
# -- General configuration ---------------------------------------------------
2828

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
setup(
77
name="Levenshtein",
8-
version="0.22.0",
8+
version="0.23.0",
99
url="https://github.com/maxbachmann/Levenshtein",
1010
author="Max Bachmann",
11-
install_requires=["rapidfuzz >= 2.3.0, < 4.0.0"],
11+
install_requires=["rapidfuzz >= 3.1.0, < 4.0.0"],
1212
author_email="contact@maxbachmann.de",
1313
description="Python extension for computing string edit distances and similarities.",
1414
long_description=readme,

src/Levenshtein/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
__author__: str = "Max Bachmann"
1818
__license__: str = "GPL"
19-
__version__: str = "0.22.0"
19+
__version__: str = "0.23.0"
2020

2121
import rapidfuzz.distance.Levenshtein as _Levenshtein
2222
import rapidfuzz.distance.Indel as _Indel
@@ -166,7 +166,7 @@ def ratio(s1, s2, *, processor=None, score_cutoff=None):
166166
)
167167

168168

169-
def hamming(s1, s2, *, processor=None, score_cutoff=None):
169+
def hamming(s1, s2, *, pad=True, processor=None, score_cutoff=None):
170170
"""
171171
Calculates the Hamming distance between two strings.
172172
The hamming distance is defined as the number of positions
@@ -179,6 +179,10 @@ def hamming(s1, s2, *, processor=None, score_cutoff=None):
179179
First string to compare.
180180
s2 : Sequence[Hashable]
181181
Second string to compare.
182+
pad : bool, optional
183+
should strings be padded if there is a length difference.
184+
If pad is False and strings have a different length
185+
a ValueError is thrown instead. Default is True.
182186
processor: callable, optional
183187
Optional callable that is used to preprocess the strings before
184188
comparing them. Default is None, which deactivates this behaviour.
@@ -198,7 +202,7 @@ def hamming(s1, s2, *, processor=None, score_cutoff=None):
198202
ValueError
199203
If s1 and s2 have a different length
200204
"""
201-
return _Hamming.distance(s1, s2, processor=processor, score_cutoff=score_cutoff)
205+
return _Hamming.distance(s1, s2, pad=pad, processor=processor, score_cutoff=score_cutoff)
202206

203207

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

0 commit comments

Comments
 (0)