-
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?
Conversation
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 for your PR!
just left a couple of comments
) -> Any | Self: | ||
if isinstance(item, (int, slice, Sequence)): | ||
return self._from_native_object(self._native_series.__getitem__(item)) | ||
return self._from_native_object(self._native_series.__getitem__(item.to_numpy())) |
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 becoming NaN
with to_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
spl = pl.Series([1, 2, 3]) | ||
assert spl[spl[0, 1]].equals(pl.Series([2, 3])) |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Using to_native()
instead of to_numpy()
allows the following tests to pass, but my complete lack of knowledge on numpy, narwhals, polars and related subjects makes me unsure they are correct and show expected behavior:
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?
What type of PR is this? (check all applicable)
Related issues
Checklist
If you have comments or can explain your changes, please do so below
This PR allows passing
Series
toSeries.__getitem__
and adds a test. I'm not sure about how/where to document the changes, any suggestions?