Skip to content

Commit 1dc31ba

Browse files
SNOW-1924268: Add support for list values in Series.str.__getitem__ (#3130)
1 parent bce369c commit 1dc31ba

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
### Snowpark pandas API Updates
1212

13+
#### New Features
14+
15+
- Added support for list values in `Series.str.__getitem__` (`Series.str[...]`).
16+
1317
## 1.29.0 (2025-03-05)
1418

1519
### Snowpark Python API Updates

docs/source/modin/supported/series_str_supported.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ the method in the left column.
1515
| (Series.str) | | |
1616
+-----------------------------+---------------------------------+----------------------------------------------------+
1717
| ``__getitem__`` | P | ``N`` if the `key` parameter is set to a non-int |
18-
| | | scalar value. |
18+
| | | scalar value. Only string and list data values are|
19+
| | | supported. All column values must be of the same |
20+
| | | type. |
1921
+-----------------------------+---------------------------------+----------------------------------------------------+
2022
| ``capitalize`` | Y | |
2123
+-----------------------------+---------------------------------+----------------------------------------------------+

tests/integ/modin/series/test_str_accessor.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,47 @@ def test_str___getitem___string_key():
250250
snow_ser.str["a"]
251251

252252

253+
@pytest.mark.parametrize(
254+
"key",
255+
[
256+
None,
257+
[1, 2],
258+
(1, 2),
259+
{1: "a", 2: "b"},
260+
-100,
261+
-2,
262+
-1,
263+
0,
264+
1,
265+
2,
266+
100,
267+
slice(None, None, None),
268+
slice(0, -1, 1),
269+
slice(-100, 100, 1),
270+
],
271+
)
272+
@sql_count_checker(query_count=1)
273+
def test_str___getitem___list(key):
274+
native_ser = native_pd.Series([["a", "b"], ["c", "d", None], None, []])
275+
snow_ser = pd.Series(native_ser)
276+
eval_snowpark_pandas_result(
277+
snow_ser,
278+
native_ser,
279+
lambda ser: ser.str[key],
280+
)
281+
282+
283+
@sql_count_checker(query_count=0)
284+
def test_str___getitem___list_neg():
285+
native_ser = native_pd.Series([["a", "b"], ["c", "d", None], None, []])
286+
snow_ser = pd.Series(native_ser)
287+
with pytest.raises(
288+
NotImplementedError,
289+
match="does not yet support 'step!=1' for list values",
290+
):
291+
snow_ser.str[slice(None, None, 2)]
292+
293+
253294
@pytest.mark.parametrize(
254295
"pat",
255296
[

0 commit comments

Comments
 (0)