Skip to content

Commit 5dd4173

Browse files
authored
Add some dtypes (#179)
* add some dtypes * remove DType import (just use the DType class from the same file) * bool8 and bool1 * bool1, bool8 -> bool
1 parent 591b23b commit 5dd4173

File tree

3 files changed

+76
-13
lines changed

3 files changed

+76
-13
lines changed

spec/API_specification/dataframe_api/__init__.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from .dataframe_object import *
1010
from .groupby_object import *
1111

12-
from ._types import DType
13-
1412

1513
__all__ = [
1614
"__dataframe_api_version",
@@ -19,6 +17,18 @@
1917
"dataframe_from_dict",
2018
"is_null",
2119
"null",
20+
"DType",
21+
"Int64",
22+
"Int32",
23+
"Int16",
24+
"Int8",
25+
"UInt64",
26+
"UInt32",
27+
"UInt16",
28+
"UInt8",
29+
"Float64",
30+
"Float32",
31+
"Bool",
2232
]
2333

2434

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

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
"""
@@ -369,56 +370,56 @@ def all(self, *, skip_nulls: bool = True) -> bool:
369370
If column is not boolean.
370371
"""
371372

372-
def min(self, *, skip_nulls: bool = True) -> DType:
373+
def min(self, *, skip_nulls: bool = True) -> Scalar:
373374
"""
374375
Reduction returns a scalar. Any data type that supports comparisons
375376
must be supported. The returned value has the same dtype as the column.
376377
"""
377378

378-
def max(self, *, skip_nulls: bool = True) -> DType:
379+
def max(self, *, skip_nulls: bool = True) -> Scalar:
379380
"""
380381
Reduction returns a scalar. Any data type that supports comparisons
381382
must be supported. The returned value has the same dtype as the column.
382383
"""
383384

384-
def sum(self, *, skip_nulls: bool = True) -> DType:
385+
def sum(self, *, skip_nulls: bool = True) -> Scalar:
385386
"""
386387
Reduction returns a scalar. Must be supported for numerical and
387388
datetime data types. The returned value has the same dtype as the
388389
column.
389390
"""
390391

391-
def prod(self, *, skip_nulls: bool = True) -> DType:
392+
def prod(self, *, skip_nulls: bool = True) -> Scalar:
392393
"""
393394
Reduction returns a scalar. Must be supported for numerical data types.
394395
The returned value has the same dtype as the column.
395396
"""
396397

397-
def median(self, *, skip_nulls: bool = True) -> DType:
398+
def median(self, *, skip_nulls: bool = True) -> Scalar:
398399
"""
399400
Reduction returns a scalar. Must be supported for numerical and
400401
datetime data types. Returns a float for numerical data types, and
401402
datetime (with the appropriate timedelta format string) for datetime
402403
dtypes.
403404
"""
404405

405-
def mean(self, *, skip_nulls: bool = True) -> DType:
406+
def mean(self, *, skip_nulls: bool = True) -> Scalar:
406407
"""
407408
Reduction returns a scalar. Must be supported for numerical and
408409
datetime data types. Returns a float for numerical data types, and
409410
datetime (with the appropriate timedelta format string) for datetime
410411
dtypes.
411412
"""
412413

413-
def std(self, *, skip_nulls: bool = True) -> DType:
414+
def std(self, *, skip_nulls: bool = True) -> Scalar:
414415
"""
415416
Reduction returns a scalar. Must be supported for numerical and
416417
datetime data types. Returns a float for numerical data types, and
417418
datetime (with the appropriate timedelta format string) for datetime
418419
dtypes.
419420
"""
420421

421-
def var(self, *, skip_nulls: bool = True) -> DType:
422+
def var(self, *, skip_nulls: bool = True) -> Scalar:
422423
"""
423424
Reduction returns a scalar. Must be supported for numerical and
424425
datetime data types. Returns a float for numerical data types, and

spec/API_specification/index.rst

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

2032
The ``DataFrame``, ``Column`` and ``GroupBy`` objects have the following
2133
methods and attributes:

0 commit comments

Comments
 (0)