-
Notifications
You must be signed in to change notification settings - Fork 146
feat: Improve DataFrame.__getitem__
consistency
#2393
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: Improve DataFrame.__getitem__
consistency
#2393
Conversation
Yes please π I'm pretty sure these were on the chopping block from |
β¦whals into pr/MarcoGorelli/2393
narwhals/_compliant/dataframe.py
Outdated
is_native_series = self.__narwhals_namespace__()._series._is_native | ||
if isinstance(rows, int): | ||
compliant = compliant._gather([rows]) | ||
elif isinstance(rows, (slice, range)): | ||
compliant = compliant._gather_slice(rows) | ||
|
||
elif is_sequence_like_ints(rows) or is_native_series(rows): | ||
compliant = compliant._gather(rows) |
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.
Feel like I didn't do a good enough job documenting this pattern
narwhals/narwhals/_compliant/namespace.py
Lines 146 to 158 in 26d97e5
@overload | |
def from_native(self, data: NativeFrameT, /) -> EagerDataFrameT: ... | |
@overload | |
def from_native(self, data: NativeSeriesT, /) -> EagerSeriesT: ... | |
def from_native( | |
self, data: NativeFrameT | NativeSeriesT | Any, / | |
) -> EagerDataFrameT | EagerSeriesT: | |
if self._dataframe._is_native(data): | |
return self._dataframe.from_native(data, context=self) | |
elif self._series._is_native(data): | |
return self._series.from_native(data, context=self) | |
msg = f"Unsupported type: {type(data).__name__!r}" | |
raise TypeError(msg) |
DataFrame.__getitem__
consistencyDataFrame.__getitem__
consistency
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.
@MarcoGorelli I think this PR will be super useful for scikit-learn.
Do you also envision to allow for boolean masks, especially for row indexing? (Not a must, but - again - useful.)
Thanks for your feedback!
Maybe, in the meantime you can use |
thanks all for comments π really appreciate it! especially:
EDIT: I stripped down the commit message to avoid it containing 97 commits (to avoid |
All of these are equivalent, follow-up to (#2393)
closes #2405
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