From f3743836f06c3a96603f55c775863cc6b150f123 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 10 May 2023 14:57:52 +0200 Subject: [PATCH 1/7] add column.dtype --- spec/API_specification/dataframe_api/column_object.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/API_specification/dataframe_api/column_object.py b/spec/API_specification/dataframe_api/column_object.py index e402cbf6..b46354d2 100644 --- a/spec/API_specification/dataframe_api/column_object.py +++ b/spec/API_specification/dataframe_api/column_object.py @@ -54,6 +54,12 @@ def __iter__(self) -> NoReturn: """ raise NotImplementedError("'__iter__' is intentionally not implemented.") + @property + def dtype(self) -> dtype: + """ + Return data type of column. + """ + def get_rows(self, indices: Column[int]) -> Column: """ Select a subset of rows, similar to `ndarray.take`. From 59b3b29af929934893d3172613ebaf5901ea4cc3 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Fri, 12 May 2023 00:03:53 +0200 Subject: [PATCH 2/7] make function, dont shadow dtype type --- spec/API_specification/dataframe_api/column_object.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/API_specification/dataframe_api/column_object.py b/spec/API_specification/dataframe_api/column_object.py index b46354d2..f76afc25 100644 --- a/spec/API_specification/dataframe_api/column_object.py +++ b/spec/API_specification/dataframe_api/column_object.py @@ -54,8 +54,7 @@ def __iter__(self) -> NoReturn: """ raise NotImplementedError("'__iter__' is intentionally not implemented.") - @property - def dtype(self) -> dtype: + def get_dtype(self) -> dtype: """ Return data type of column. """ From 6ca02849d6855b15bf36199a5a358276a9d96651 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 15 May 2023 15:50:20 +0100 Subject: [PATCH 3/7] :truck: rename dtype to DType --- .../API_specification/dataframe_api/_types.py | 2 +- .../dataframe_api/column_object.py | 25 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/spec/API_specification/dataframe_api/_types.py b/spec/API_specification/dataframe_api/_types.py index 0987ecaa..66ea7b0f 100644 --- a/spec/API_specification/dataframe_api/_types.py +++ b/spec/API_specification/dataframe_api/_types.py @@ -23,7 +23,7 @@ array = TypeVar("array") Scalar = TypeVar("Scalar") device = TypeVar("device") -dtype = TypeVar("dtype") +DType = TypeVar("DType") SupportsDLPack = TypeVar("SupportsDLPack") SupportsBufferProtocol = TypeVar("SupportsBufferProtocol") PyCapsule = TypeVar("PyCapsule") diff --git a/spec/API_specification/dataframe_api/column_object.py b/spec/API_specification/dataframe_api/column_object.py index f76afc25..f846048b 100644 --- a/spec/API_specification/dataframe_api/column_object.py +++ b/spec/API_specification/dataframe_api/column_object.py @@ -2,7 +2,7 @@ from typing import NoReturn, Sequence -from ._types import Scalar, dtype +from ._types import Scalar, DType __all__ = ['Column'] @@ -18,7 +18,7 @@ class Column: """ @classmethod - def from_sequence(cls, sequence: Sequence[object], dtype: dtype) -> Column: + def from_sequence(cls, sequence: Sequence[object], dtype: DType) -> Column: """ Construct Column from sequence of elements. @@ -54,7 +54,8 @@ def __iter__(self) -> NoReturn: """ raise NotImplementedError("'__iter__' is intentionally not implemented.") - def get_dtype(self) -> dtype: + @property + def dtype(self) -> DType: """ Return data type of column. """ @@ -70,7 +71,7 @@ def get_rows(self, indices: Column[int]) -> Column: """ ... - def get_value(self, row_number: int) -> dtype: + def get_value(self, row_number: int) -> DType: """ Select the value at a row number, similar to `ndarray.__getitem__()`. @@ -341,32 +342,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) -> DType: """ 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) -> DType: """ 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) -> DType: """ 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) -> DType: """ 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) -> DType: """ Reduction returns a scalar. Must be supported for numerical and datetime data types. Returns a float for numerical data types, and @@ -374,7 +375,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) -> DType: """ Reduction returns a scalar. Must be supported for numerical and datetime data types. Returns a float for numerical data types, and @@ -382,7 +383,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) -> DType: """ Reduction returns a scalar. Must be supported for numerical and datetime data types. Returns a float for numerical data types, and @@ -390,7 +391,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) -> DType: """ Reduction returns a scalar. Must be supported for numerical and datetime data types. Returns a float for numerical data types, and From 0cd6bbc1edede7ad767b56d36775a5748e59e004 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 15 May 2023 15:52:00 +0100 Subject: [PATCH 4/7] fixup --- spec/API_specification/dataframe_api/_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/API_specification/dataframe_api/_types.py b/spec/API_specification/dataframe_api/_types.py index 66ea7b0f..2874ba4c 100644 --- a/spec/API_specification/dataframe_api/_types.py +++ b/spec/API_specification/dataframe_api/_types.py @@ -57,7 +57,7 @@ def __len__(self, /) -> int: "Sequence", "array", "device", - "dtype", + "DType", "ellipsis", "Enum", ] From 61069f39fd46f9a7dcf2cfde06c2a8cfbd4d17ff Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 15 May 2023 15:56:39 +0100 Subject: [PATCH 5/7] more fixups --- spec/API_specification/dataframe_api/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/API_specification/dataframe_api/__init__.py b/spec/API_specification/dataframe_api/__init__.py index df239329..dc53d176 100644 --- a/spec/API_specification/dataframe_api/__init__.py +++ b/spec/API_specification/dataframe_api/__init__.py @@ -9,7 +9,7 @@ from .dataframe_object import * from .groupby_object import * -from ._types import dtype +from ._types import DType __dataframe_api_version__: str = "YYYY.MM" @@ -18,7 +18,7 @@ conforming implementation adheres. """ -def column_from_sequence(sequence: Sequence[object], *, dtype: dtype) -> Column: +def column_from_sequence(sequence: Sequence[object], *, dtype: DType) -> Column: """ Construct Column from sequence of elements. @@ -28,7 +28,7 @@ def column_from_sequence(sequence: Sequence[object], *, dtype: dtype) -> Column: Sequence of elements. Each element must be of the specified ``dtype``, the corresponding Python builtin scalar type, or coercible to that Python scalar type. - dtype : str + dtype : DType Dtype of result. Must be specified. Returns From 9823466559692b1895ca9630306920f9d325df3f Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 15 May 2023 16:02:07 +0100 Subject: [PATCH 6/7] add to nitpick ignore? --- spec/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/conf.py b/spec/conf.py index c44feb81..8d3d7800 100644 --- a/spec/conf.py +++ b/spec/conf.py @@ -75,7 +75,7 @@ ('py:class', 'array'), ('py:class', 'DataFrame'), ('py:class', 'device'), - ('py:class', 'dtype'), + ('py:class', 'DType'), ('py:class', 'NestedSequence'), ('py:class', 'collections.abc.Sequence'), ('py:class', 'PyCapsule'), From d75176a0f76b7301f5c6c6b29ceb877687d9927c Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 15 May 2023 16:10:16 +0100 Subject: [PATCH 7/7] try if type-checking --- spec/API_specification/dataframe_api/column_object.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/API_specification/dataframe_api/column_object.py b/spec/API_specification/dataframe_api/column_object.py index 7c4353c1..0d8a8a27 100644 --- a/spec/API_specification/dataframe_api/column_object.py +++ b/spec/API_specification/dataframe_api/column_object.py @@ -1,8 +1,9 @@ from __future__ import annotations -from typing import NoReturn, Sequence +from typing import NoReturn, Sequence, TYPE_CHECKING -from ._types import Scalar, DType +if TYPE_CHECKING: + from ._types import Scalar, DType __all__ = ['Column']