Skip to content

Commit 9673b35

Browse files
authored
Add indexing, assign, arithmetic methods (#94)
1 parent 8d05ee8 commit 9673b35

File tree

2 files changed

+362
-1
lines changed

2 files changed

+362
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Column:
2+
pass
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,364 @@
11
__all__ = ["DataFrame"]
22

3+
from typing import Sequence, TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
from .column_object import Column
7+
38

49
class DataFrame:
5-
pass
10+
11+
def get_column_by_name(self, name: str, /) -> Column:
12+
"""
13+
Select a column by name.
14+
15+
Parameters
16+
----------
17+
name : str
18+
19+
Returns
20+
-------
21+
Column
22+
23+
Raises
24+
------
25+
KeyError
26+
If the key is not present.
27+
"""
28+
...
29+
30+
def get_columns_by_name(self, names: Sequence[str], /) -> "DataFrame":
31+
"""
32+
Select multiple columns by name.
33+
34+
Parameters
35+
----------
36+
names : Sequence[str]
37+
38+
Returns
39+
-------
40+
DataFrame
41+
42+
Raises
43+
------
44+
KeyError
45+
If the any requested key is not present.
46+
"""
47+
...
48+
49+
def get_rows(self, indices: Sequence[int]) -> "DataFrame":
50+
"""
51+
Select a subset of rows, similar to `ndarray.take`.
52+
53+
Parameters
54+
----------
55+
indices : Sequence[int]
56+
Positions of rows to select.
57+
58+
Returns
59+
-------
60+
DataFrame
61+
62+
Notes
63+
-----
64+
Some discussion participants prefer a stricter type Column[int] for
65+
indices in order to make it easier to implement in a performant manner
66+
on GPUs.
67+
"""
68+
...
69+
70+
def slice_rows(
71+
self, start: int | None, stop: int | None, step: int | None
72+
) -> "DataFrame":
73+
"""
74+
Select a subset of rows corresponding to a slice.
75+
76+
Parameters
77+
----------
78+
start : int or None
79+
stop : int or None
80+
step : int or None
81+
82+
Returns
83+
-------
84+
DataFrame
85+
"""
86+
...
87+
88+
def get_rows_by_mask(self, mask: Column[bool]) -> "DataFrame":
89+
"""
90+
Select a subset of rows corresponding to a mask.
91+
92+
Parameters
93+
----------
94+
mask : Column[bool]
95+
96+
Returns
97+
-------
98+
DataFrame
99+
100+
Notes
101+
-----
102+
Some participants preferred a weaker type Arraylike[bool] for mask,
103+
where 'Arraylike' denotes an object adhering to the Array API standard.
104+
"""
105+
...
106+
107+
def insert(self, loc: int, label: str, value: Column) -> "DataFrame":
108+
"""
109+
Insert column into DataFrame at specified location.
110+
111+
Parameters
112+
----------
113+
loc : int
114+
Insertion index. Must verify 0 <= loc <= len(columns).
115+
label : str
116+
Label of the inserted column.
117+
value : Column
118+
"""
119+
...
120+
121+
def drop_column(self, label: str) -> "DataFrame":
122+
"""
123+
Drop the specified column.
124+
125+
Parameters
126+
----------
127+
label : str
128+
129+
Returns
130+
-------
131+
DataFrame
132+
133+
Raises
134+
------
135+
KeyError
136+
If the label is not present.
137+
"""
138+
...
139+
140+
def set_column(self, label: str, value: Column) -> "DataFrame":
141+
"""
142+
Add or replace a column.
143+
144+
Parameters
145+
----------
146+
label : str
147+
value : Column
148+
149+
Returns
150+
-------
151+
DataFrame
152+
"""
153+
...
154+
155+
def __eq__(self, other: DataFrame | "Scalar") -> "DataFrame":
156+
"""
157+
Parameters
158+
----------
159+
other : DataFrame or Scalar
160+
If DataFrame, must have same length and matching columns.
161+
"Scalar" here is defined implicitly by what scalar types are allowed
162+
for the operation by the underling dtypes.
163+
164+
Returns
165+
-------
166+
DataFrame
167+
"""
168+
...
169+
170+
def __ne__(self, other: DataFrame | "Scalar") -> "DataFrame":
171+
"""
172+
Parameters
173+
----------
174+
other : DataFrame or Scalar
175+
If DataFrame, must have same length and matching columns.
176+
"Scalar" here is defined implicitly by what scalar types are allowed
177+
for the operation by the underling dtypes.
178+
179+
Returns
180+
-------
181+
DataFrame
182+
"""
183+
...
184+
185+
def __ge__(self, other: DataFrame | "Scalar") -> "DataFrame":
186+
"""
187+
Parameters
188+
----------
189+
other : DataFrame or Scalar
190+
If DataFrame, must have same length and matching columns.
191+
"Scalar" here is defined implicitly by what scalar types are allowed
192+
for the operation by the underling dtypes.
193+
194+
Returns
195+
-------
196+
DataFrame
197+
"""
198+
...
199+
200+
def __gt__(self, other: DataFrame | "Scalar") -> "DataFrame":
201+
"""
202+
Parameters
203+
----------
204+
other : DataFrame or Scalar
205+
If DataFrame, must have same length and matching columns.
206+
"Scalar" here is defined implicitly by what scalar types are allowed
207+
for the operation by the underling dtypes.
208+
209+
Returns
210+
-------
211+
DataFrame
212+
"""
213+
...
214+
215+
def __le__(self, other: DataFrame | "Scalar") -> "DataFrame":
216+
"""
217+
Parameters
218+
----------
219+
other : DataFrame or Scalar
220+
If DataFrame, must have same length and matching columns.
221+
"Scalar" here is defined implicitly by what scalar types are allowed
222+
for the operation by the underling dtypes.
223+
224+
Returns
225+
-------
226+
DataFrame
227+
"""
228+
...
229+
230+
def __lt__(self, other: DataFrame | "Scalar") -> "DataFrame":
231+
"""
232+
Parameters
233+
----------
234+
other : DataFrame or Scalar
235+
If DataFrame, must have same length and matching columns.
236+
"Scalar" here is defined implicitly by what scalar types are allowed
237+
for the operation by the underling dtypes.
238+
239+
Returns
240+
-------
241+
DataFrame
242+
"""
243+
...
244+
245+
def __add__(self, other: DataFrame | "Scalar") -> "DataFrame":
246+
"""
247+
Parameters
248+
----------
249+
other : DataFrame or Scalar
250+
If DataFrame, must have same length and matching columns.
251+
"Scalar" here is defined implicitly by what scalar types are allowed
252+
for the operation by the underling dtypes.
253+
254+
Returns
255+
-------
256+
DataFrame
257+
"""
258+
...
259+
260+
def __sub__(self, other: DataFrame | "Scalar") -> "DataFrame":
261+
"""
262+
Parameters
263+
----------
264+
other : DataFrame or Scalar
265+
If DataFrame, must have same length and matching columns.
266+
"Scalar" here is defined implicitly by what scalar types are allowed
267+
for the operation by the underling dtypes.
268+
269+
Returns
270+
-------
271+
DataFrame
272+
"""
273+
...
274+
275+
def __mul__(self, other: DataFrame | "Scalar") -> "DataFrame":
276+
"""
277+
Parameters
278+
----------
279+
other : DataFrame or Scalar
280+
If DataFrame, must have same length and matching columns.
281+
"Scalar" here is defined implicitly by what scalar types are allowed
282+
for the operation by the underling dtypes.
283+
284+
Returns
285+
-------
286+
DataFrame
287+
"""
288+
...
289+
290+
def __truediv__(self, other: DataFrame | "Scalar") -> "DataFrame":
291+
"""
292+
Parameters
293+
----------
294+
other : DataFrame or Scalar
295+
If DataFrame, must have same length and matching columns.
296+
"Scalar" here is defined implicitly by what scalar types are allowed
297+
for the operation by the underling dtypes.
298+
299+
Returns
300+
-------
301+
DataFrame
302+
"""
303+
...
304+
305+
def __floordiv__(self, other: DataFrame | "Scalar") -> "DataFrame":
306+
"""
307+
Parameters
308+
----------
309+
other : DataFrame or Scalar
310+
If DataFrame, must have same length and matching columns.
311+
"Scalar" here is defined implicitly by what scalar types are allowed
312+
for the operation by the underling dtypes.
313+
314+
Returns
315+
-------
316+
DataFrame
317+
"""
318+
...
319+
320+
def __pow__(self, other: DataFrame | "Scalar") -> "DataFrame":
321+
"""
322+
Parameters
323+
----------
324+
other : DataFrame or Scalar
325+
If DataFrame, must have same length and matching columns.
326+
"Scalar" here is defined implicitly by what scalar types are allowed
327+
for the operation by the underling dtypes.
328+
329+
Returns
330+
-------
331+
DataFrame
332+
"""
333+
...
334+
335+
def __mod__(self, other: DataFrame | "Scalar") -> "DataFrame":
336+
"""
337+
Parameters
338+
----------
339+
other : DataFrame or Scalar
340+
If DataFrame, must have same length and matching columns.
341+
"Scalar" here is defined implicitly by what scalar types are allowed
342+
for the operation by the underling dtypes.
343+
344+
Returns
345+
-------
346+
DataFrame
347+
"""
348+
...
349+
350+
def __divmod__(self, other: DataFrame | "Scalar") -> tuple["DataFrame", "DataFrame"]:
351+
"""
352+
Parameters
353+
----------
354+
other : DataFrame or Scalar
355+
If DataFrame, must have same length and matching columns.
356+
"Scalar" here is defined implicitly by what scalar types are allowed
357+
for the operation by the underling dtypes.
358+
359+
Returns
360+
-------
361+
DataFrame
362+
DataFrame
363+
"""
364+
...

0 commit comments

Comments
 (0)