Skip to content

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
merged 11 commits into from
May 4, 2023
48 changes: 47 additions & 1 deletion spec/API_specification/dataframe_api/column_object.py
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 Scalar, dtype

Expand Down Expand Up @@ -35,6 +35,52 @@ def from_sequence(cls, sequence: Sequence[object], dtype: dtype) -> Column:
-------
Column
"""
...

def __len__(self) -> int:
"""
Return the number of rows.
"""

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.
"""
...

def get_value(self, row_number: int) -> dtype:
"""
Select the value at a row number, similar to `ndarray.__getitem__(<int>)`.

Parameters
----------
row_number : int
Row number of value to return.

Returns
-------
dtype
Depends on the dtype of the Column, and may vary
across implementations.
"""
...

def __eq__(self, other: Column | Scalar) -> Column:
"""
Expand Down