diff --git a/spec/API_specification/dataframe_api/__init__.py b/spec/API_specification/dataframe_api/__init__.py index afca3cb0..ef0f03c9 100644 --- a/spec/API_specification/dataframe_api/__init__.py +++ b/spec/API_specification/dataframe_api/__init__.py @@ -9,8 +9,6 @@ from .dataframe_object import * from .groupby_object import * -from ._types import DType - __all__ = [ "__dataframe_api_version", @@ -19,6 +17,18 @@ "dataframe_from_dict", "isnull", "null", + "DType", + "Int64", + "Int32", + "Int16", + "Int8", + "UInt64", + "UInt32", + "UInt16", + "UInt8", + "Float64", + "Float32", + "Bool", ] @@ -129,3 +139,43 @@ def isnull(value: object, /) -> bool: implements the dataframe API standard, False otherwise. """ + +########## +# Dtypes # +########## + +class DType: + """Base class for all dtypes.""" + +class Int64(DType): + """Integer type with 64 bits of precision.""" + +class Int32(DType): + """Integer type with 32 bits of precision.""" + +class Int16(DType): + """Integer type with 16 bits of precision.""" + +class Int8(DType): + """Integer type with 8 bits of precision.""" + +class UInt64(DType): + """Unsigned integer type with 64 bits of precision.""" + +class UInt32(DType): + """Unsigned integer type with 32 bits of precision.""" + +class UInt16(DType): + """Unsigned integer type with 16 bits of precision.""" + +class UInt8(DType): + """Unsigned integer type with 8 bits of precision.""" + +class Float64(DType): + """Floating point type with 64 bits of precision.""" + +class Float32(DType): + """Floating point type with 32 bits of precision.""" + +class Bool(DType): + """Boolean type with 8 bits of precision.""" diff --git a/spec/API_specification/dataframe_api/column_object.py b/spec/API_specification/dataframe_api/column_object.py index 3fec189c..62704cb6 100644 --- a/spec/API_specification/dataframe_api/column_object.py +++ b/spec/API_specification/dataframe_api/column_object.py @@ -3,7 +3,8 @@ from typing import NoReturn, Sequence, TYPE_CHECKING if TYPE_CHECKING: - from ._types import Scalar, DType + from ._types import Scalar + from . import DType __all__ = ['Column'] @@ -52,7 +53,7 @@ def get_rows(self, indices: Column[int]) -> Column: """ ... - def get_value(self, row_number: int) -> DType: + def get_value(self, row_number: int) -> Scalar: """ Select the value at a row number, similar to `ndarray.__getitem__()`. @@ -63,7 +64,7 @@ def get_value(self, row_number: int) -> DType: Returns ------- - dtype + Scalar Depends on the dtype of the Column, and may vary across implementations. """ @@ -323,32 +324,32 @@ def all(self, *, skip_nulls: bool = True) -> bool: If column is not boolean. """ - def min(self, *, skip_nulls: bool = True) -> DType: + def min(self, *, skip_nulls: bool = True) -> Scalar: """ Reduction returns a scalar. Any data type that supports comparisons must be supported. The returned value has the same dtype as the column. """ - def max(self, *, skip_nulls: bool = True) -> DType: + def max(self, *, skip_nulls: bool = True) -> Scalar: """ Reduction returns a scalar. Any data type that supports comparisons must be supported. The returned value has the same dtype as the column. """ - def sum(self, *, skip_nulls: bool = True) -> DType: + def sum(self, *, skip_nulls: bool = True) -> Scalar: """ Reduction returns a scalar. Must be supported for numerical and datetime data types. The returned value has the same dtype as the column. """ - def prod(self, *, skip_nulls: bool = True) -> DType: + def prod(self, *, skip_nulls: bool = True) -> Scalar: """ Reduction returns a scalar. Must be supported for numerical data types. The returned value has the same dtype as the column. """ - def median(self, *, skip_nulls: bool = True) -> DType: + def median(self, *, skip_nulls: bool = True) -> Scalar: """ Reduction returns a scalar. Must be supported for numerical and datetime data types. Returns a float for numerical data types, and @@ -356,7 +357,7 @@ def median(self, *, skip_nulls: bool = True) -> DType: dtypes. """ - def mean(self, *, skip_nulls: bool = True) -> DType: + def mean(self, *, skip_nulls: bool = True) -> Scalar: """ Reduction returns a scalar. Must be supported for numerical and datetime data types. Returns a float for numerical data types, and @@ -364,7 +365,7 @@ def mean(self, *, skip_nulls: bool = True) -> DType: dtypes. """ - def std(self, *, skip_nulls: bool = True) -> DType: + def std(self, *, skip_nulls: bool = True) -> Scalar: """ Reduction returns a scalar. Must be supported for numerical and datetime data types. Returns a float for numerical data types, and @@ -372,7 +373,7 @@ def std(self, *, skip_nulls: bool = True) -> DType: dtypes. """ - def var(self, *, skip_nulls: bool = True) -> DType: + def var(self, *, skip_nulls: bool = True) -> Scalar: """ Reduction returns a scalar. Must be supported for numerical and datetime data types. Returns a float for numerical data types, and diff --git a/spec/API_specification/index.rst b/spec/API_specification/index.rst index 16a0cb61..235d72dd 100644 --- a/spec/API_specification/index.rst +++ b/spec/API_specification/index.rst @@ -16,6 +16,18 @@ of objects and functions in the top-level namespace. The latter are: __dataframe_api_version__ isnull null + DType + Int64 + Int32 + Int16 + Int8 + UInt64 + UInt32 + UInt16 + UInt8 + Float64 + Float32 + Bool The ``DataFrame``, ``Column`` and ``GroupBy`` objects have the following methods and attributes: