Skip to content

Commit

Permalink
Closes Bears-R-Us#3827: rename flatten to split
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpotts committed Oct 9, 2024
1 parent 828e612 commit 5398e96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions arkouda/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ def fullmatch(self, pattern: Union[bytes, str_scalars]) -> Match:
return self._get_matcher(pattern).get_match(MatchType.FULLMATCH, self)

@typechecked()
def split(
def regex_split(
self, pattern: Union[bytes, str_scalars], maxsplit: int = 0, return_segments: bool = False
) -> Union[Strings, Tuple]:
"""
Expand Down Expand Up @@ -1609,7 +1609,7 @@ def flatten(
re.compile(delimiter)
except Exception as e:
raise ValueError(e)
return self.split(delimiter, return_segments=return_segments)
return self.regex_split(delimiter, return_segments=return_segments)
else:
cmd = "segmentedFlatten"
repMsg = cast(
Expand Down
8 changes: 4 additions & 4 deletions tests/regex_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_empty_string_patterns(self):
# peel is broken on one char strings with patterns that match empty string
# str split and non-regex flatten don't work with empty separator, so
# it makes sense for the regex versions to return a value error
for fn in "peel", "split", "flatten":
for fn in "peel", "regex_split", "flatten":
func = getattr(ak_str, fn)
with pytest.raises(ValueError):
func(pattern, regex=True) if fn in has_regex_arg else func(pattern)
Expand All @@ -92,7 +92,7 @@ def test_empty_string_patterns(self):
"endswith",
"findall",
"peel",
"split",
"regex_split",
"flatten",
):
for s, pat in zip([ak.array([""]), ak.array(["0 String 0"])], ["", "$"]):
Expand Down Expand Up @@ -133,13 +133,13 @@ def test_caputure_groups(self):
# verify fluid programming with Match object doesn't raise a RuntimeError
ak.array(["1_2___", "____", "3", "__4___5____6___7", ""]).search("_+").find_matches()

def test_split(self):
def test_regex_split(self):
strings = ak.array(
["", "____", "_1_2____", "3___4___", "5", "__6__", "___7", "__8___9____10____11"]
)
pattern = "_+"
maxsplit = 3
split, split_map = strings.split(pattern, maxsplit, return_segments=True)
split, split_map = strings.regex_split(pattern, maxsplit, return_segments=True)
for i in range(strings.size):
re_split = re.split(pattern, strings[i], maxsplit)
ak_split = (
Expand Down

0 comments on commit 5398e96

Please sign in to comment.