-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow passing Series to Series.__getitem__ #1533
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
import polars as pl | ||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
|
||
|
||
def test_getitem() -> None: | ||
spl = pl.Series([1, 2, 3]) | ||
assert spl[spl[0, 1]].equals(pl.Series([2, 3])) | ||
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we check what happens when there's missing values too please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using spl = pl.Series([1, None, 3])
assert spl[spl[0, 1]].equals(pl.Series([None, None]))
snw = nw.from_native(spl, series_only=True)
assert snw[snw[0, 1]].to_native().equals(pl.Series([None, None])) What's your take on this? |
||
|
||
snw = nw.from_native(spl, series_only=True) | ||
assert snw[snw[0, 1]].to_native().equals(pl.Series([2, 3])) | ||
|
||
spl = pl.Series([1, 2, 3]) | ||
snw = nw.from_native(spl, series_only=True) | ||
assert pytest.raises(TypeError, lambda: snw[snw[True, False]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π€ not sure we should be converting to numpy here
I'm not totally sure what we should be doing instead though, sorry, will need to investigate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I had doubts about this too and picked a solution that seemed to work without actually understanding the consequences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems using
item.to_native()
instead works, and also solves an issue with missing values becomingNaN
withto_numpy()
. Do you think it's acceptable? Any other corner cases to cover with tests?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks - i'll check, to be careful we get the details right here