Skip to content

Commit abeca76

Browse files
authored
Merge pull request numpy#26903 from lysnikolaou/fix-strip-ufunc
Fix off-by-one error in amount of characters in strip
2 parents 7147ddc + b22b27d commit abeca76

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

numpy/_core/src/umath/string_buffer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,9 +1281,7 @@ string_lrstrip_chars(Buffer<enc> buf1, Buffer<enc> buf2, Buffer<enc> out, STRIPT
12811281
}
12821282
num_bytes -= traverse_buf.num_bytes_next_character();
12831283
j--;
1284-
if (j > 0) {
1285-
traverse_buf--;
1286-
}
1284+
traverse_buf--;
12871285
}
12881286
}
12891287

numpy/_core/tests/test_strings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ def test_endswith(self, a, suffix, start, end, out, dt):
463463
("xyxzx", "x", "yxzx"),
464464
(["xyzzyhelloxyzzy", "hello"], ["xyz", "xyz"],
465465
["helloxyzzy", "hello"]),
466+
(["ba", "ac", "baa", "bba"], "b", ["a", "ac", "aa", "a"]),
466467
])
467468
def test_lstrip(self, a, chars, out, dt):
468469
a = np.array(a, dtype=dt)
@@ -488,6 +489,7 @@ def test_lstrip(self, a, chars, out, dt):
488489
("xyxzx", "x", "xyxz"),
489490
(["xyzzyhelloxyzzy", "hello"], ["xyz", "xyz"],
490491
["xyzzyhello", "hello"]),
492+
(["ab", "ac", "aab", "abb"], "b", ["a", "ac", "aa", "a"]),
491493
])
492494
def test_rstrip(self, a, chars, out, dt):
493495
a = np.array(a, dtype=dt)
@@ -511,6 +513,7 @@ def test_rstrip(self, a, chars, out, dt):
511513
("xyxzx", "x", "yxz"),
512514
(["xyzzyhelloxyzzy", "hello"], ["xyz", "xyz"],
513515
["hello", "hello"]),
516+
(["bab", "ac", "baab", "bbabb"], "b", ["a", "ac", "aa", "a"]),
514517
])
515518
def test_strip(self, a, chars, out, dt):
516519
a = np.array(a, dtype=dt)

0 commit comments

Comments
 (0)