From eb03b45b2c8b8fd5b2d1a6131bf21d7dd1894669 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Tue, 17 Oct 2023 10:29:07 +0300 Subject: [PATCH 1/5] drive by: put __all__ in alphabetical order --- .../dataframe_api/__init__.py | 57 ++++++++++++------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/spec/API_specification/dataframe_api/__init__.py b/spec/API_specification/dataframe_api/__init__.py index 7f4d17d4..b65a2bf3 100644 --- a/spec/API_specification/dataframe_api/__init__.py +++ b/spec/API_specification/dataframe_api/__init__.py @@ -14,32 +14,33 @@ from .typing import DType __all__ = [ - "__dataframe_api_version__", - "DataFrame", - "Column", - "column_from_sequence", - "column_from_1d_array", - "concat", - "dataframe_from_dict", - "dataframe_from_2d_array", - "is_null", - "null", - "Int64", - "Int32", - "Int16", - "Int8", - "UInt64", - "UInt32", - "UInt16", - "UInt8", - "Float64", - "Float32", "Bool", + "Column", + "DataFrame", "Date", "Datetime", "Duration", + "Float32", + "Float64", + "Int16", + "Int32", + "Int64", + "Int8", "String", + "UInt16", + "UInt32", + "UInt64", + "UInt8", + "__dataframe_api_version__", + "column_from_1d_array", + "column_from_sequence", + "concat", + "dataframe_from_2d_array", + "dataframe_from_dict", + "date", "is_dtype", + "is_null", + "null", ] @@ -241,3 +242,19 @@ def is_dtype(dtype: DType, kind: str | tuple[str, ...]) -> bool: ------- bool """ + +def date(year: int, month: int, day: int) -> Any: + """ + Create date object which can be used for filtering. + + Examples + -------- + >>> df: DataFrame + >>> namespace = df.__dataframe_namespace__() + >>> mask = ( + ... (df.get_column_by_name('date') >= namespace.date(2020, 1, 1)) + ... (df.get_column_by_name('date') < namespace.date(2021, 1, 1)) + ... ) + >>> df.filter(mask) + """ + From 686a89a70d58b29d3a7a250453e6556f9a4c83cc Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:46:27 +0300 Subject: [PATCH 2/5] add to namespace, type return as scalar --- spec/API_specification/dataframe_api/__init__.py | 6 +++--- spec/API_specification/dataframe_api/typing.py | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/API_specification/dataframe_api/__init__.py b/spec/API_specification/dataframe_api/__init__.py index b65a2bf3..80561aee 100644 --- a/spec/API_specification/dataframe_api/__init__.py +++ b/spec/API_specification/dataframe_api/__init__.py @@ -11,7 +11,7 @@ from .dtypes import * if TYPE_CHECKING: - from .typing import DType + from .typing import DType, Scalar __all__ = [ "Bool", @@ -243,7 +243,7 @@ def is_dtype(dtype: DType, kind: str | tuple[str, ...]) -> bool: bool """ -def date(year: int, month: int, day: int) -> Any: +def date(year: int, month: int, day: int) -> Scalar: """ Create date object which can be used for filtering. @@ -253,7 +253,7 @@ def date(year: int, month: int, day: int) -> Any: >>> namespace = df.__dataframe_namespace__() >>> mask = ( ... (df.get_column_by_name('date') >= namespace.date(2020, 1, 1)) - ... (df.get_column_by_name('date') < namespace.date(2021, 1, 1)) + ... & (df.get_column_by_name('date') < namespace.date(2021, 1, 1)) ... ) >>> df.filter(mask) """ diff --git a/spec/API_specification/dataframe_api/typing.py b/spec/API_specification/dataframe_api/typing.py index 4b157a9d..c6bace93 100644 --- a/spec/API_specification/dataframe_api/typing.py +++ b/spec/API_specification/dataframe_api/typing.py @@ -148,6 +148,9 @@ def is_null(value: object, /) -> bool: def is_dtype(dtype: Any, kind: str | tuple[str, ...]) -> bool: ... + @staticmethod + def date(year: int, month: int, day: int) -> Scalar: + ... class SupportsDataFrameAPI(Protocol): def __dataframe_consortium_standard__( From 99d3ce9a87c64a100cf632ed3d9b81535da1e2db Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 25 Oct 2023 08:54:55 +0100 Subject: [PATCH 3/5] remove outdated type ignore --- spec/API_specification/examples/tpch/q5.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/API_specification/examples/tpch/q5.py b/spec/API_specification/examples/tpch/q5.py index cdca0806..0ed69b67 100644 --- a/spec/API_specification/examples/tpch/q5.py +++ b/spec/API_specification/examples/tpch/q5.py @@ -58,8 +58,8 @@ def query( == result.get_column_by_name("s_nationkey") ) & (result.get_column_by_name("r_name") == "ASIA") - & (result.get_column_by_name("o_orderdate") >= namespace.date(1994, 1, 1)) # type: ignore - & (result.get_column_by_name("o_orderdate") < namespace.date(1995, 1, 1)) # type: ignore + & (result.get_column_by_name("o_orderdate") >= namespace.date(1994, 1, 1)) + & (result.get_column_by_name("o_orderdate") < namespace.date(1995, 1, 1)) ) result = result.filter(mask) From 079d320221c85204a657f1b5659c805787943808 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 25 Oct 2023 08:56:14 +0100 Subject: [PATCH 4/5] note range of support --- spec/API_specification/dataframe_api/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/API_specification/dataframe_api/__init__.py b/spec/API_specification/dataframe_api/__init__.py index edbaef4f..5cae30b9 100644 --- a/spec/API_specification/dataframe_api/__init__.py +++ b/spec/API_specification/dataframe_api/__init__.py @@ -240,6 +240,8 @@ def date(year: int, month: int, day: int) -> Scalar: """ Create date object which can be used for filtering. + The full 32-bit signed integer range of dates should be supported. + Examples -------- >>> df: DataFrame From 68985108d2af9d17878b7b2bc0de1abc73beba01 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Wed, 25 Oct 2023 18:06:26 +0100 Subject: [PATCH 5/5] Update spec/API_specification/dataframe_api/__init__.py Co-authored-by: Keith Kraus --- spec/API_specification/dataframe_api/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/API_specification/dataframe_api/__init__.py b/spec/API_specification/dataframe_api/__init__.py index 5cae30b9..74dc4346 100644 --- a/spec/API_specification/dataframe_api/__init__.py +++ b/spec/API_specification/dataframe_api/__init__.py @@ -240,7 +240,7 @@ def date(year: int, month: int, day: int) -> Scalar: """ Create date object which can be used for filtering. - The full 32-bit signed integer range of dates should be supported. + The full 32-bit signed integer range of days since epoch should be supported (between -5877641-06-23 and 5881580-07-11 inclusive). Examples --------