Skip to content

Commit 6e75449

Browse files
committed
add some dtypes
1 parent 2950673 commit 6e75449

File tree

3 files changed

+74
-11
lines changed

3 files changed

+74
-11
lines changed

spec/API_specification/dataframe_api/__init__.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
"dataframe_from_dict",
2020
"isnull",
2121
"null",
22+
"Dtype",
23+
"Int64",
24+
"Int32",
25+
"Int16",
26+
"Int8",
27+
"UInt64",
28+
"UInt32",
29+
"UInt16",
30+
"UInt8",
31+
"Float64",
32+
"Float32",
2233
]
2334

2435

@@ -129,3 +140,43 @@ def isnull(value: object, /) -> bool:
129140
implements the dataframe API standard, False otherwise.
130141
131142
"""
143+
144+
##########
145+
# Dtypes #
146+
##########
147+
148+
class DType:
149+
"""Base class for all dtypes."""
150+
151+
class Int64(DType):
152+
"""Integer type with 64 bits of precision."""
153+
154+
class Int32(DType):
155+
"""Integer type with 32 bits of precision."""
156+
157+
class Int16(DType):
158+
"""Integer type with 16 bits of precision."""
159+
160+
class Int8(DType):
161+
"""Integer type with 8 bits of precision."""
162+
163+
class UInt64(DType):
164+
"""Unsigned integer type with 64 bits of precision."""
165+
166+
class UInt32(DType):
167+
"""Unsigned integer type with 32 bits of precision."""
168+
169+
class UInt16(DType):
170+
"""Unsigned integer type with 16 bits of precision."""
171+
172+
class UInt8(DType):
173+
"""Unsigned integer type with 8 bits of precision."""
174+
175+
class Float64(DType):
176+
"""Floating point type with 64 bits of precision."""
177+
178+
class Float32(DType):
179+
"""Floating point type with 32 bits of precision."""
180+
181+
class Bool(DType):
182+
"""Boolean type."""

spec/API_specification/dataframe_api/column_object.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from typing import NoReturn, Sequence, TYPE_CHECKING
44

55
if TYPE_CHECKING:
6-
from ._types import Scalar, DType
6+
from ._types import Scalar
7+
from . import DType
78

89

910
__all__ = ['Column']
@@ -52,7 +53,7 @@ def get_rows(self, indices: Column[int]) -> Column:
5253
"""
5354
...
5455

55-
def get_value(self, row_number: int) -> DType:
56+
def get_value(self, row_number: int) -> Scalar:
5657
"""
5758
Select the value at a row number, similar to `ndarray.__getitem__(<int>)`.
5859
@@ -63,7 +64,7 @@ def get_value(self, row_number: int) -> DType:
6364
6465
Returns
6566
-------
66-
dtype
67+
Scalar
6768
Depends on the dtype of the Column, and may vary
6869
across implementations.
6970
"""
@@ -323,56 +324,56 @@ def all(self, *, skip_nulls: bool = True) -> bool:
323324
If column is not boolean.
324325
"""
325326

326-
def min(self, *, skip_nulls: bool = True) -> DType:
327+
def min(self, *, skip_nulls: bool = True) -> Scalar:
327328
"""
328329
Reduction returns a scalar. Any data type that supports comparisons
329330
must be supported. The returned value has the same dtype as the column.
330331
"""
331332

332-
def max(self, *, skip_nulls: bool = True) -> DType:
333+
def max(self, *, skip_nulls: bool = True) -> Scalar:
333334
"""
334335
Reduction returns a scalar. Any data type that supports comparisons
335336
must be supported. The returned value has the same dtype as the column.
336337
"""
337338

338-
def sum(self, *, skip_nulls: bool = True) -> DType:
339+
def sum(self, *, skip_nulls: bool = True) -> Scalar:
339340
"""
340341
Reduction returns a scalar. Must be supported for numerical and
341342
datetime data types. The returned value has the same dtype as the
342343
column.
343344
"""
344345

345-
def prod(self, *, skip_nulls: bool = True) -> DType:
346+
def prod(self, *, skip_nulls: bool = True) -> Scalar:
346347
"""
347348
Reduction returns a scalar. Must be supported for numerical data types.
348349
The returned value has the same dtype as the column.
349350
"""
350351

351-
def median(self, *, skip_nulls: bool = True) -> DType:
352+
def median(self, *, skip_nulls: bool = True) -> Scalar:
352353
"""
353354
Reduction returns a scalar. Must be supported for numerical and
354355
datetime data types. Returns a float for numerical data types, and
355356
datetime (with the appropriate timedelta format string) for datetime
356357
dtypes.
357358
"""
358359

359-
def mean(self, *, skip_nulls: bool = True) -> DType:
360+
def mean(self, *, skip_nulls: bool = True) -> Scalar:
360361
"""
361362
Reduction returns a scalar. Must be supported for numerical and
362363
datetime data types. Returns a float for numerical data types, and
363364
datetime (with the appropriate timedelta format string) for datetime
364365
dtypes.
365366
"""
366367

367-
def std(self, *, skip_nulls: bool = True) -> DType:
368+
def std(self, *, skip_nulls: bool = True) -> Scalar:
368369
"""
369370
Reduction returns a scalar. Must be supported for numerical and
370371
datetime data types. Returns a float for numerical data types, and
371372
datetime (with the appropriate timedelta format string) for datetime
372373
dtypes.
373374
"""
374375

375-
def var(self, *, skip_nulls: bool = True) -> DType:
376+
def var(self, *, skip_nulls: bool = True) -> Scalar:
376377
"""
377378
Reduction returns a scalar. Must be supported for numerical and
378379
datetime data types. Returns a float for numerical data types, and

spec/API_specification/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ of objects and functions in the top-level namespace. The latter are:
1616
__dataframe_api_version__
1717
isnull
1818
null
19+
DType
20+
Int64
21+
Int32
22+
Int16
23+
Int8
24+
UInt64
25+
UInt32
26+
UInt16
27+
UInt8
28+
Float64
29+
Float32
1930

2031
The ``DataFrame``, ``Column`` and ``GroupBy`` objects have the following
2132
methods and attributes:

0 commit comments

Comments
 (0)