You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [8]: spl=pl.Series([1,2,3])
In [9]: spl[spl[0, 1]]
Out[9]:
shape: (2,)
Series: '' [i64]
[
23
]
But Narwhals gives an incomprehensible error message:
In [13]: snw=nw.from_native(spl, series_only=True)
In [14]: snw[snw[0, 1]]
---------------------------------------------------------------------------TypeErrorTraceback (mostrecentcalllast)
CellIn[14], line1---->1snw[snw[0, 1]]
File~/scratch/.venv/lib/python3.12/site-packages/narwhals/series.py:72, inSeries.__getitem__(self, idx)
70ifisinstance(idx, int):
71returnself._compliant_series[idx]
--->72returnself._from_compliant_series(self._compliant_series[idx])
File~/scratch/.venv/lib/python3.12/site-packages/narwhals/_polars/series.py:126, inPolarsSeries.__getitem__(self, item)
125def__getitem__(self: Self, item: int|slice|Sequence[int]) ->Any|Self:
-->126returnself._from_native_object(self._native_series.__getitem__(item))
File~/scratch/.venv/lib/python3.12/site-packages/polars/series/series.py:1282, inSeries.__getitem__(self, key)
1254def__getitem__(
1255self, key: SingleIndexSelector|MultiIndexSelector1256 ) ->Any|Series:
1257""" 1258 Get part of the Series as a new Series or scalar. 1259 (...) 1280 ] 1281 """->1282returnget_series_item_by_key(self, key)
File~/scratch/.venv/lib/python3.12/site-packages/polars/_utils/getitem.py:90, inget_series_item_by_key(s, key)
87return_select_elements_by_index(s, indices)
89msg=f"cannot select elements using key of type {type(key).__name__!r}: {key!r}"--->90raiseTypeError(msg)
TypeError: cannotselectelementsusingkeyoftype'Series': ┌─────────────────────────────────────────┐
|NarwhalsSeries||Use`.to_native()`toseenativeoutput|
└─────────────────────────────────────────┘
I think we should:
allow this if the Series is of integral dtypes
raise if the Series is boolean, advising users to use Series.filter instead
The text was updated successfully, but these errors were encountered:
With Polars we can do:
But Narwhals gives an incomprehensible error message:
I think we should:
Series.filter
insteadThe text was updated successfully, but these errors were encountered: