Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion narwhals/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,11 @@ def is_slice_index(obj: Any) -> TypeIs[_SliceIndex]:
return isinstance(obj, slice) and (
isinstance(obj.start, int)
or isinstance(obj.stop, int)
or (isinstance(obj.step, int) and obj.start is None and obj.stop is None)
or (
isinstance(obj.step, (int, NoneType))
and obj.start is None
and obj.stop is None
)
)


Expand Down Expand Up @@ -2141,3 +2145,6 @@ def __repr__(self) -> str: # pragma: no cover
# the "no_default" sentinel should typically be used when one of the valid parameter
# values is None, as otherwise we cannot determine if the caller has set that value.
no_default = _NoDefault.no_default

# Can be imported from types in Python 3.10
NoneType = type(None)
5 changes: 4 additions & 1 deletion tests/series_only/getitem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

import narwhals as nw
from tests.utils import assert_equal_data
from tests.utils import assert_equal_data, assert_equal_series

if TYPE_CHECKING:
from tests.utils import ConstructorEager
Expand Down Expand Up @@ -38,6 +38,9 @@ def test_by_slice(constructor_eager: ConstructorEager) -> None:
result = {"b": df[[], 1]}
expected = {"b": []}
assert_equal_data(result, expected)
result_ser = df[:, 0][slice(None)]
expected_ser = [1, 2, 3]
assert_equal_series(result_ser, expected_ser, name="a")


def test_getitem_arrow_scalar() -> None:
Expand Down
Loading