@@ -152,13 +152,18 @@ def ends_with(self, suffix: str) -> SeriesT:
152152 self ._narwhals_series ._compliant_series .str .ends_with (suffix )
153153 )
154154
155- def contains (self , pattern : str , * , literal : bool = False ) -> SeriesT :
155+ def contains (self , pattern : str | SeriesT , * , literal : bool = False ) -> SeriesT :
156156 r"""Check if string contains a substring that matches a pattern.
157157
158158 Arguments:
159- pattern: A Character sequence or valid regular expression pattern.
159+ pattern: A Character sequence, valid regular expression pattern, or another
160+ Series.
160161 literal: If True, treats the pattern as a literal string.
161- If False, assumes the pattern is a regular expression.
162+ If False, assumes the pattern is a regular expression.
163+
164+ Warning:
165+ Passing a Series as `pattern` is only supported by Polars. Other backends
166+ will raise a `TypeError`.
162167
163168 Examples:
164169 >>> import pyarrow as pa
@@ -176,7 +181,9 @@ def contains(self, pattern: str, *, literal: bool = False) -> SeriesT:
176181 ]
177182 """
178183 return self ._narwhals_series ._with_compliant (
179- self ._narwhals_series ._compliant_series .str .contains (pattern , literal = literal )
184+ self ._narwhals_series ._compliant_series .str .contains (
185+ self ._extract_compliant (pattern ), literal = literal
186+ )
180187 )
181188
182189 def slice (self , offset : int , length : int | None = None ) -> SeriesT :
0 commit comments