Skip to content

Commit

Permalink
Refined the type of string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Dec 7, 2024
1 parent 38a4261 commit ecaff24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions sklearn2pmml/feature_extraction/text/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ def test_call(self):
self.assertEqual(("one", ), matcher("one++"))
self.assertEqual(("one", "two", "three"), matcher("one two three"))
self.assertEqual(("one", "_t", "w", "o_", "three"), matcher(",one _t,w.o_ three."))
matcher = Matcher("\w{2,}")
matcher = Matcher(r"\w{2,}")
self.assertEqual(("one", "two", "three"), matcher("one two three"))
self.assertEqual(("one", "_t", "o_", "three"), matcher(",one _t,w.o_ three."))
matcher = Matcher("\w{4,}")
matcher = Matcher(r"\w{4,}")
self.assertEqual(("three", ), matcher("one two three"))
self.assertEqual(("three", ), matcher(",one _t,w.o_ three."))

def test_pickle(self):
matcher = Matcher("\S+")
self.assertEqual("\S+", matcher.word_re)
matcher = Matcher(r"\S+")
self.assertEqual(r"\S+", matcher.word_re)
matcher_clone = _clone(matcher)
self.assertEqual("\S+", matcher_clone.word_re)
self.assertEqual(r"\S+", matcher_clone.word_re)

class SplitterTest(TestCase):

Expand All @@ -50,7 +50,7 @@ def test_call(self):
self.assertEqual(("one", "t,w.o", "three"), splitter(",one _t,w.o_ three."))

def test_pickle(self):
splitter = Splitter("\W")
self.assertEqual("\W", splitter.word_separator_re)
splitter = Splitter(r"\W")
self.assertEqual(r"\W", splitter.word_separator_re)
splitter_clone = _clone(splitter)
self.assertEqual("\W", splitter_clone.word_separator_re)
self.assertEqual(r"\W", splitter_clone.word_separator_re)
2 changes: 1 addition & 1 deletion sklearn2pmml/preprocessing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def transform(self, X):
class WordCountTransformer(StringTransformer):
"""Count tokens."""

def __init__(self, word_pattern = "\w+", non_word_pattern = "\W+"):
def __init__(self, word_pattern = r"\w+", non_word_pattern = r"\W+"):
super(WordCountTransformer, self).__init__()
self.word_pattern = word_pattern
self.non_word_pattern = non_word_pattern
Expand Down

0 comments on commit ecaff24

Please sign in to comment.