Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit e31df92

Browse files
authored
Merge pull request #277 from datafold/nov4_fix_alphanum_bug
Bugfix in alphanums (reported by Guarav Singh)
2 parents 16f4ee0 + a8c6efc commit e31df92

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

data_diff/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def numberToAlphanum(num: int, base: str = alphanums) -> str:
6666
return "".join(base[i] for i in digits[::-1])
6767

6868

69-
def alphanumToNumber(alphanum: str, base: str) -> int:
69+
def alphanumToNumber(alphanum: str, base: str = alphanums) -> int:
7070
num = 0
7171
for c in alphanum:
7272
num = num * len(base) + base.index(c)
@@ -82,8 +82,8 @@ def justify_alphanums(s1: str, s2: str):
8282

8383
def alphanums_to_numbers(s1: str, s2: str):
8484
s1, s2 = justify_alphanums(s1, s2)
85-
n1 = alphanumToNumber(s1, alphanums)
86-
n2 = alphanumToNumber(s2, alphanums)
85+
n1 = alphanumToNumber(s1)
86+
n2 = alphanumToNumber(s2)
8787
return n1, n2
8888

8989

@@ -121,9 +121,9 @@ def __add__(self, other: "Union[ArithAlphanumeric, int]") -> "ArithAlphanumeric"
121121
if isinstance(other, int):
122122
if other != 1:
123123
raise NotImplementedError("not implemented for arbitrary numbers")
124-
lastchar = self._str[-1] if self._str else alphanums[0]
125-
s = self._str[:-1] + alphanums[alphanums.index(lastchar) + other]
126-
return self.new(s)
124+
num = alphanumToNumber(self._str)
125+
return self.new(numberToAlphanum(num + 1))
126+
127127
return NotImplemented
128128

129129
def range(self, other: "ArithAlphanumeric", count: int):

tests/test_diff_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def setUp(self):
414414
super().setUp()
415415

416416
self.src_table = src_table = table(self.table_src_path, schema={"id": str, "text_comment": str})
417-
self.new_alphanum = "aBcDeFgHiJ"
417+
self.new_alphanum = "aBcDeFgHiz"
418418

419419
values = []
420420
for i in range(0, 10000, 1000):

0 commit comments

Comments
 (0)