-
Notifications
You must be signed in to change notification settings - Fork 21
add __len__ and __getitem__ to Column #140
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
Merged
MarcoGorelli
merged 11 commits into
data-apis:main
from
MarcoGorelli:column-getitem-and-len
May 4, 2023
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e689f0b
add __len__ and __getitem__ to Column
1fa1030
remove trailing whitespace
faaf599
Revert "remove trailing whitespace"
8b2413b
type getitems row
27a1ece
let __getitem__ take sequence of int
73e7987
Revert "let __getitem__ take sequence of int"
ce443f8
add get_rows
2796b0d
Merge remote-tracking branch 'upstream/main' into column-getitem-and-len
41eb73d
Merge remote-tracking branch 'upstream/main' into column-getitem-and-len
d5440e8
Merge remote-tracking branch 'upstream/main' into column-getitem-and-len
995ec3a
doc fixup
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
from typing import NoReturn | ||
|
||
class Column: | ||
pass | ||
def __len__(self) -> int: | ||
""" | ||
Return the number of rows. | ||
""" | ||
|
||
def __getitem__(self, row) -> object: | ||
""" | ||
Get the element at row index `row`. | ||
""" | ||
|
||
def __iter__(self) -> NoReturn: | ||
""" | ||
Iterate over elements. | ||
|
||
This is intentionally "poisoned" to discourage inefficient code patterns. | ||
|
||
Raises | ||
------ | ||
NotImplementedError | ||
""" | ||
raise NotImplementedError("'__iter__' is intentionally not implemented.") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What is the expected type of "row" here? An integer?
I wonder if we should have more explicit methods than
__getitem__
since intuitively people will try to feed both scalars and Sequences / Columns into it.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.
oops, forgot to annotate that one, thanks
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.
could you expand 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.
Historically, Pandas and other dataframe libraries have allowed passing scalar-like objects here and getting a scalar-like object in return or passing Sequence-like / Column-like objects here and getting Column-like objects in return. I.E. for Pandas:
For our DataFrame object we have the
get_rows
method that takes a Sequence-like (should probably take a Column-like) where we could presumably have the same function for our Column object, and then instead of using__getitem__
we could have something likeget_element
orget_scalar
or something like that.If we wanted to keep the
__getitem__
method I would suggest we handle both the Scalar-like and Sequence-like / Column-like cases as opposed to just the Scalar-like.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.
yeah, I came across this - I'll open a separate issue
Uh oh!
There was an error while loading. Please reload this page.
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.
I've pushed a commit but am not overly keen on it, how about
Column.get_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.
added another commit with get_rows, better to avoid overloads if we can help it