|
2 | 2 |
|
3 | 3 | from typing import TYPE_CHECKING |
4 | 4 |
|
| 5 | +from narwhals._pandas_like.utils import get_dtype_backend |
5 | 6 | from narwhals._pandas_like.utils import to_datetime |
| 7 | +from narwhals.utils import Implementation |
6 | 8 |
|
7 | 9 | if TYPE_CHECKING: |
8 | 10 | from typing_extensions import Self |
@@ -61,6 +63,27 @@ def slice(self: Self, offset: int, length: int | None) -> PandasLikeSeries: |
61 | 63 | self._compliant_series._native_series.str.slice(start=offset, stop=stop), |
62 | 64 | ) |
63 | 65 |
|
| 66 | + def split(self: Self, by: str) -> PandasLikeSeries: |
| 67 | + if ( |
| 68 | + self._compliant_series._implementation is not Implementation.CUDF |
| 69 | + ): # pragma: no cover |
| 70 | + dtype_backend = get_dtype_backend( |
| 71 | + self._compliant_series._native_series.dtype, |
| 72 | + self._compliant_series._implementation, |
| 73 | + ) |
| 74 | + if dtype_backend != "pyarrow": |
| 75 | + msg = ( |
| 76 | + "This operation requires a pyarrow-backed series. " |
| 77 | + "Please refer to https://narwhals-dev.github.io/narwhals/api-reference/narwhals/#narwhals.maybe_convert_dtypes " |
| 78 | + "and ensure you are using dtype_backend='pyarrow'. " |
| 79 | + "Additionally, make sure you have pandas version 1.5+ and pyarrow installed. " |
| 80 | + ) |
| 81 | + raise TypeError(msg) |
| 82 | + |
| 83 | + return self._compliant_series._from_native_series( |
| 84 | + self._compliant_series._native_series.str.split(pat=by), |
| 85 | + ) |
| 86 | + |
64 | 87 | def to_datetime(self: Self, format: str | None) -> PandasLikeSeries: # noqa: A002 |
65 | 88 | return self._compliant_series._from_native_series( |
66 | 89 | to_datetime(self._compliant_series._implementation)( |
|
0 commit comments