Skip to content

Commit b54bb26

Browse files
Add namespace.date (#289)
* drive by: put __all__ in alphabetical order * add to namespace, type return as scalar * remove outdated type ignore * note range of support * Update spec/API_specification/dataframe_api/__init__.py Co-authored-by: Keith Kraus <[email protected]> --------- Co-authored-by: Keith Kraus <[email protected]>
1 parent 0087b3a commit b54bb26

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

spec/API_specification/dataframe_api/__init__.py

+40-21
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,36 @@
1111
from .dtypes import *
1212

1313
if TYPE_CHECKING:
14-
from .typing import DType
14+
from .typing import DType, Scalar
1515

1616
__all__ = [
17-
"__dataframe_api_version__",
18-
"DataFrame",
19-
"Column",
20-
"column_from_sequence",
21-
"column_from_1d_array",
22-
"concat",
23-
"dataframe_from_columns",
24-
"dataframe_from_2d_array",
25-
"is_null",
26-
"null",
27-
"Int64",
28-
"Int32",
29-
"Int16",
30-
"Int8",
31-
"UInt64",
32-
"UInt32",
33-
"UInt16",
34-
"UInt8",
35-
"Float64",
36-
"Float32",
3717
"Bool",
18+
"Column",
19+
"DataFrame",
3820
"Date",
3921
"Datetime",
4022
"Duration",
23+
"Float32",
24+
"Float64",
25+
"Int16",
26+
"Int32",
27+
"Int64",
28+
"Int8",
4129
"String",
30+
"UInt16",
31+
"UInt32",
32+
"UInt64",
33+
"UInt8",
34+
"__dataframe_api_version__",
35+
"column_from_1d_array",
36+
"column_from_sequence",
37+
"concat",
38+
"dataframe_from_2d_array",
39+
"dataframe_from_columns",
40+
"date",
4241
"is_dtype",
42+
"is_null",
43+
"null",
4344
]
4445

4546

@@ -234,3 +235,21 @@ def is_dtype(dtype: DType, kind: str | tuple[str, ...]) -> bool:
234235
-------
235236
bool
236237
"""
238+
239+
def date(year: int, month: int, day: int) -> Scalar:
240+
"""
241+
Create date object which can be used for filtering.
242+
243+
The full 32-bit signed integer range of days since epoch should be supported (between -5877641-06-23 and 5881580-07-11 inclusive).
244+
245+
Examples
246+
--------
247+
>>> df: DataFrame
248+
>>> namespace = df.__dataframe_namespace__()
249+
>>> mask = (
250+
... (df.get_column_by_name('date') >= namespace.date(2020, 1, 1))
251+
... & (df.get_column_by_name('date') < namespace.date(2021, 1, 1))
252+
... )
253+
>>> df.filter(mask)
254+
"""
255+

spec/API_specification/dataframe_api/typing.py

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ def is_null(value: object, /) -> bool:
161161
def is_dtype(dtype: Any, kind: str | tuple[str, ...]) -> bool:
162162
...
163163

164+
@staticmethod
165+
def date(year: int, month: int, day: int) -> Scalar:
166+
...
164167

165168
class SupportsDataFrameAPI(Protocol):
166169
def __dataframe_consortium_standard__(

spec/API_specification/examples/tpch/q5.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def query(
5858
== result.get_column_by_name("s_nationkey")
5959
)
6060
& (result.get_column_by_name("r_name") == "ASIA")
61-
& (result.get_column_by_name("o_orderdate") >= namespace.date(1994, 1, 1)) # type: ignore
62-
& (result.get_column_by_name("o_orderdate") < namespace.date(1995, 1, 1)) # type: ignore
61+
& (result.get_column_by_name("o_orderdate") >= namespace.date(1994, 1, 1))
62+
& (result.get_column_by_name("o_orderdate") < namespace.date(1995, 1, 1))
6363
)
6464
result = result.filter(mask)
6565

0 commit comments

Comments
 (0)