Skip to content

Commit e6de485

Browse files
authored
add __len__ and __getitem__ to Column (#140)
* add __len__ and __getitem__ to Column * remove trailing whitespace * Revert "remove trailing whitespace" This reverts commit 1fa1030. * type getitems row * let __getitem__ take sequence of int * Revert "let __getitem__ take sequence of int" This reverts commit 27a1ece. * add get_rows * doc fixup --------- Co-authored-by: MarcoGorelli <>
1 parent cc07b49 commit e6de485

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

spec/API_specification/dataframe_api/column_object.py

+47-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Sequence
3+
from typing import NoReturn, Sequence
44

55
from ._types import Scalar, dtype
66

@@ -35,6 +35,52 @@ def from_sequence(cls, sequence: Sequence[object], dtype: dtype) -> Column:
3535
-------
3636
Column
3737
"""
38+
...
39+
40+
def __len__(self) -> int:
41+
"""
42+
Return the number of rows.
43+
"""
44+
45+
def __iter__(self) -> NoReturn:
46+
"""
47+
Iterate over elements.
48+
49+
This is intentionally "poisoned" to discourage inefficient code patterns.
50+
51+
Raises
52+
------
53+
NotImplementedError
54+
"""
55+
raise NotImplementedError("'__iter__' is intentionally not implemented.")
56+
57+
def get_rows(self, indices: Column[int]) -> Column:
58+
"""
59+
Select a subset of rows, similar to `ndarray.take`.
60+
61+
Parameters
62+
----------
63+
indices : Column[int]
64+
Positions of rows to select.
65+
"""
66+
...
67+
68+
def get_value(self, row_number: int) -> dtype:
69+
"""
70+
Select the value at a row number, similar to `ndarray.__getitem__(<int>)`.
71+
72+
Parameters
73+
----------
74+
row_number : int
75+
Row number of value to return.
76+
77+
Returns
78+
-------
79+
dtype
80+
Depends on the dtype of the Column, and may vary
81+
across implementations.
82+
"""
83+
...
3884

3985
def __eq__(self, other: Column | Scalar) -> Column:
4086
"""

0 commit comments

Comments
 (0)