Repository: pola-rs/polars
File: py-polars/src/polars/expr/string.py (Python)

Code before:
        ╞════════════╪═══════════╪═════════════════════╡
        │ discontent ┆ [0]       ┆ [0, 4, 0]           │
        └────────────┴───────────┴─────────────────────┘
        >>> df = pl.DataFrame(
        ...     {
        ...         "values": ["discontent", "rhapsody"],
        ...         "patterns": [
        ...             ["winter", "disco", "onte", "discontent"],
        ...             ["rhap", "ody", "coalesce"],
        ...         ],
        ...     }
        ... )
        >>> df.select(pl.col("values").str.find_many("patterns"))
        shape: (2, 1)
        ┌───────────┐
        │ values    │
        │ ---       │
        │ list[u32] │
        ╞═══════════╡
        │ [0]       │
        │ [0, 5]    │
        └───────────┘
        """
        if overlapping and leftmost:
            msg = "can not match overlapping patterns when leftmost == True"
            raise TypeError(msg)
        patterns_pyexpr = parse_into_expression(patterns, str_as_lit=False)
        return wrap_expr(
            self._pyexpr.str_find_many(
                patterns_pyexpr, ascii_case_insensitive, overlapping, leftmost
            )
        )

    def join(self, delimiter: str = "", *, ignore_nulls: bool = True) -> Expr:
        """
        Vertically concatenate the string values in the column to a single string value.

        Parameters
        ----------
        delimiter
            The delimiter to insert between consecutive string values.
        ignore_nulls
            Ignore null values (default).
            If set to `False`, null values will be propagated. This means that
            if the column contains any null values, the output is null.

        Returns
        -------
        Expr
            Expression of data type :class:`String`.


Review comment (suggestion):
This should not be a `TypeError`, but a `ValueError`.

Code after:
            )
        )

    @unstable()
    def find_many(
        self,
        patterns: IntoExpr,
        *,
        ascii_case_insensitive: bool = False,
        overlapping: bool = False,
        leftmost: bool = False,
    ) -> Expr:
        """
        Use the Aho-Corasick algorithm to find many matches.

        The function will return the bytes offset of the start of each match.
        The return type will be `List<UInt32>`

        Parameters
        ----------
        patterns
            String patterns to search.
        ascii_case_insensitive
            Enable ASCII-aware case-insensitive matching.
            When this option is enabled, searching will be performed without respect
            to case for ASCII letters (a-z and A-Z) only.
        overlapping
            Whether matches may overlap.
        leftmost
            Guarantees in case there are overlapping matches that the leftmost match
            is used. In case there are multiple candidates for the leftmost match
            the pattern which comes first in patterns is used. May not be used
            together with overlapping = True.

        Notes
        -----
        This method supports matching on string literals only, and does not support
        regular expression matching.

        Examples
        --------
        >>> _ = pl.Config.set_fmt_str_lengths(100)
        >>> df = pl.DataFrame({"values": ["discontent"]})
        >>> patterns = ["winter", "disco", "onte", "discontent"]
        >>> df.with_columns(
        ...     pl.col("values")
        ...     .str.find_many(patterns, overlapping=False)
        ...     .alias("matches"),
        ...     pl.col("values")
        ...     .str.find_many(patterns, overlapping=True)
        ...     .alias("matches_overlapping"),