Skip to content

Add some dtypes #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions spec/API_specification/dataframe_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
from .dataframe_object import *
from .groupby_object import *

from ._types import DType


__all__ = [
"__dataframe_api_version",
Expand All @@ -19,6 +17,18 @@
"dataframe_from_dict",
"isnull",
"null",
"DType",
"Int64",
"Int32",
"Int16",
"Int8",
"UInt64",
"UInt32",
"UInt16",
"UInt8",
"Float64",
"Float32",
"Bool",
]


Expand Down Expand Up @@ -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."""
23 changes: 12 additions & 11 deletions spec/API_specification/dataframe_api/column_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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__(<int>)`.

Expand All @@ -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.
"""
Expand Down Expand Up @@ -323,56 +324,56 @@ 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
datetime (with the appropriate timedelta format string) for datetime
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
datetime (with the appropriate timedelta format string) for datetime
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
datetime (with the appropriate timedelta format string) for datetime
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
Expand Down
12 changes: 12 additions & 0 deletions spec/API_specification/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down