-
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
Changes from 9 commits
e689f0b
1fa1030
faaf599
8b2413b
27a1ece
73e7987
ce443f8
2796b0d
41eb73d
d5440e8
995ec3a
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Sequence | ||
from typing import NoReturn, Sequence | ||
|
||
from ._types import dtype | ||
|
||
|
@@ -35,3 +35,37 @@ def from_sequence(cls, sequence: Sequence[object], dtype: dtype) -> Column: | |
------- | ||
Column | ||
""" | ||
... | ||
|
||
def __len__(self) -> int: | ||
""" | ||
Return the number of rows. | ||
""" | ||
|
||
def __getitem__(self, row: int) -> object: | ||
""" | ||
Get the element at row index `key`. | ||
""" | ||
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. It still feels a bit funky to me to only support the scalar case via 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. there's already 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. Another use case for getitem (or separate method) is slicing (#89 indicates adding a separate method for that as well) |
||
|
||
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.") | ||
|
||
def get_rows(self, indices: Column[int]) -> Column: | ||
""" | ||
Select a subset of rows, similar to `ndarray.take`. | ||
|
||
Parameters | ||
---------- | ||
indices : Column[int] | ||
Positions of rows to select. | ||
""" | ||
... |
Uh oh!
There was an error while loading. Please reload this page.