Skip to content

Commit 16aabbf

Browse files
authored
add Column.dtype (data-apis#166)
1 parent 2aeaf00 commit 16aabbf

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

spec/API_specification/dataframe_api/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .dataframe_object import *
1010
from .groupby_object import *
1111

12-
from ._types import dtype
12+
from ._types import DType
1313

1414

1515
__dataframe_api_version__: str = "YYYY.MM"
@@ -38,7 +38,7 @@ def concat(dataframes: Sequence[DataFrame]) -> DataFrame:
3838
"""
3939
...
4040

41-
def column_from_sequence(sequence: Sequence[object], *, dtype: dtype) -> Column:
41+
def column_from_sequence(sequence: Sequence[object], *, dtype: DType) -> Column:
4242
"""
4343
Construct Column from sequence of elements.
4444
@@ -48,7 +48,7 @@ def column_from_sequence(sequence: Sequence[object], *, dtype: dtype) -> Column:
4848
Sequence of elements. Each element must be of the specified
4949
``dtype``, the corresponding Python builtin scalar type, or
5050
coercible to that Python scalar type.
51-
dtype : str
51+
dtype : DType
5252
Dtype of result. Must be specified.
5353
5454
Returns

spec/API_specification/dataframe_api/_types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
array = TypeVar("array")
2424
Scalar = TypeVar("Scalar")
2525
device = TypeVar("device")
26-
dtype = TypeVar("dtype")
26+
DType = TypeVar("DType")
2727
SupportsDLPack = TypeVar("SupportsDLPack")
2828
SupportsBufferProtocol = TypeVar("SupportsBufferProtocol")
2929
PyCapsule = TypeVar("PyCapsule")
@@ -57,7 +57,7 @@ def __len__(self, /) -> int:
5757
"Sequence",
5858
"array",
5959
"device",
60-
"dtype",
60+
"DType",
6161
"ellipsis",
6262
"Enum",
6363
]

spec/API_specification/dataframe_api/column_object.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

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

5-
from ._types import Scalar, dtype
5+
if TYPE_CHECKING:
6+
from ._types import Scalar, DType
67

78

89
__all__ = ['Column']
@@ -34,6 +35,12 @@ def __iter__(self) -> NoReturn:
3435
"""
3536
raise NotImplementedError("'__iter__' is intentionally not implemented.")
3637

38+
@property
39+
def dtype(self) -> DType:
40+
"""
41+
Return data type of column.
42+
"""
43+
3744
def get_rows(self, indices: Column[int]) -> Column:
3845
"""
3946
Select a subset of rows, similar to `ndarray.take`.
@@ -45,7 +52,7 @@ def get_rows(self, indices: Column[int]) -> Column:
4552
"""
4653
...
4754

48-
def get_value(self, row_number: int) -> dtype:
55+
def get_value(self, row_number: int) -> DType:
4956
"""
5057
Select the value at a row number, similar to `ndarray.__getitem__(<int>)`.
5158
@@ -316,56 +323,56 @@ def all(self, *, skip_nulls: bool = True) -> bool:
316323
If column is not boolean.
317324
"""
318325

319-
def min(self, *, skip_nulls: bool = True) -> dtype:
326+
def min(self, *, skip_nulls: bool = True) -> DType:
320327
"""
321328
Reduction returns a scalar. Any data type that supports comparisons
322329
must be supported. The returned value has the same dtype as the column.
323330
"""
324331

325-
def max(self, *, skip_nulls: bool = True) -> dtype:
332+
def max(self, *, skip_nulls: bool = True) -> DType:
326333
"""
327334
Reduction returns a scalar. Any data type that supports comparisons
328335
must be supported. The returned value has the same dtype as the column.
329336
"""
330337

331-
def sum(self, *, skip_nulls: bool = True) -> dtype:
338+
def sum(self, *, skip_nulls: bool = True) -> DType:
332339
"""
333340
Reduction returns a scalar. Must be supported for numerical and
334341
datetime data types. The returned value has the same dtype as the
335342
column.
336343
"""
337344

338-
def prod(self, *, skip_nulls: bool = True) -> dtype:
345+
def prod(self, *, skip_nulls: bool = True) -> DType:
339346
"""
340347
Reduction returns a scalar. Must be supported for numerical data types.
341348
The returned value has the same dtype as the column.
342349
"""
343350

344-
def median(self, *, skip_nulls: bool = True) -> dtype:
351+
def median(self, *, skip_nulls: bool = True) -> DType:
345352
"""
346353
Reduction returns a scalar. Must be supported for numerical and
347354
datetime data types. Returns a float for numerical data types, and
348355
datetime (with the appropriate timedelta format string) for datetime
349356
dtypes.
350357
"""
351358

352-
def mean(self, *, skip_nulls: bool = True) -> dtype:
359+
def mean(self, *, skip_nulls: bool = True) -> DType:
353360
"""
354361
Reduction returns a scalar. Must be supported for numerical and
355362
datetime data types. Returns a float for numerical data types, and
356363
datetime (with the appropriate timedelta format string) for datetime
357364
dtypes.
358365
"""
359366

360-
def std(self, *, skip_nulls: bool = True) -> dtype:
367+
def std(self, *, skip_nulls: bool = True) -> DType:
361368
"""
362369
Reduction returns a scalar. Must be supported for numerical and
363370
datetime data types. Returns a float for numerical data types, and
364371
datetime (with the appropriate timedelta format string) for datetime
365372
dtypes.
366373
"""
367374

368-
def var(self, *, skip_nulls: bool = True) -> dtype:
375+
def var(self, *, skip_nulls: bool = True) -> DType:
369376
"""
370377
Reduction returns a scalar. Must be supported for numerical and
371378
datetime data types. Returns a float for numerical data types, and

spec/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
('py:class', 'array'),
7676
('py:class', 'DataFrame'),
7777
('py:class', 'device'),
78-
('py:class', 'dtype'),
78+
('py:class', 'DType'),
7979
('py:class', 'NestedSequence'),
8080
('py:class', 'collections.abc.Sequence'),
8181
('py:class', 'PyCapsule'),

0 commit comments

Comments
 (0)