Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Jarrett committed Oct 27, 2022
1 parent dff1848 commit 4207be0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 4 additions & 6 deletions dask_sql/physical/rex/core/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,10 @@ def __init__(self):
super().__init__(self.replace)

def replace(self, s, pat, repl):
if isinstance(s, str):
return s.replace(pat, repl)
elif isinstance(s, dd.Series):
return s.str.replace(pat, repl)
else:
raise TypeError("The string expression must be a string or a column name")
if is_frame(s):
s = s.str

return s.replace(pat, repl)


class OverlayOperation(Operation):
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def test_string_operations():
assert ops_mapping["substring"](a, 2) == " normal string"
assert ops_mapping["substring"](a, 2, 2) == " n"
assert ops_mapping["initcap"](a) == "A Normal String"
assert ops_mapping["replace"](a, "nor", "") == "a mal string"
assert ops_mapping["replace"](a, "normal", "new") == "a new string"
assert ops_mapping["replace"]("hello", "", "w") == "whwewlwlwow"


def test_dates():
Expand Down

0 comments on commit 4207be0

Please sign in to comment.