Skip to content

Commit 44dc8cb

Browse files
committed
add namespace protocol
1 parent 950c07d commit 44dc8cb

File tree

2 files changed

+102
-6
lines changed

2 files changed

+102
-6
lines changed

spec/API_specification/dataframe_api/_types.py

+100-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66
"""
77
from __future__ import annotations
88

9-
from dataclasses import dataclass
109
from typing import (
10+
TYPE_CHECKING,
1111
Any,
1212
List,
1313
Literal,
14+
Mapping,
1415
Optional,
16+
Protocol,
1517
Sequence,
1618
Tuple,
1719
TypeVar,
1820
Union,
19-
Protocol,
2021
)
21-
from enum import Enum
22+
23+
if TYPE_CHECKING:
24+
from .dataframe_object import DataFrame
2225

2326
# Type alias: Mypy needs Any, but for readability we need to make clear this
2427
# is a Python scalar (i.e., an instance of `bool`, `int`, `float`, `str`, etc.)
@@ -48,6 +51,100 @@ def __len__(self, /) -> int:
4851
...
4952

5053

54+
class Namespace(Protocol):
55+
__dataframe_api_version__: str
56+
57+
class DataFrame:
58+
...
59+
60+
class Column:
61+
...
62+
63+
class Int64:
64+
...
65+
66+
class Int32:
67+
...
68+
69+
class Int16:
70+
...
71+
72+
class Int8:
73+
...
74+
75+
class UInt64:
76+
...
77+
78+
class UInt32:
79+
...
80+
81+
class UInt16:
82+
...
83+
84+
class UInt8:
85+
...
86+
87+
class Float64:
88+
...
89+
90+
class Float32:
91+
...
92+
93+
class Bool:
94+
...
95+
96+
@staticmethod
97+
def concat(dataframes: Sequence[DataFrame]) -> DataFrame:
98+
...
99+
100+
@staticmethod
101+
def column_from_sequence(
102+
sequence: Sequence[Any],
103+
*,
104+
dtype: Any,
105+
name: str = "",
106+
api_version: str | None = None,
107+
) -> Column:
108+
...
109+
110+
@staticmethod
111+
def dataframe_from_dict(
112+
data: Mapping[str, Column], *, api_version: str | None = None
113+
) -> DataFrame:
114+
...
115+
116+
@staticmethod
117+
def column_from_1d_array(
118+
array: Any, *, dtype: Any, name: str = "", api_version: str | None = None
119+
) -> Column:
120+
...
121+
122+
@staticmethod
123+
def dataframe_from_2d_array(
124+
array: Any,
125+
*,
126+
names: Sequence[str],
127+
dtypes: Mapping[str, Any],
128+
api_version: str | None = None,
129+
) -> DataFrame:
130+
...
131+
132+
@staticmethod
133+
def is_null(value: object, /) -> bool:
134+
...
135+
136+
@staticmethod
137+
def is_dtype(dtype: Any, kind: str | tuple[str, ...]) -> bool:
138+
...
139+
140+
141+
class SupportsDataFrameAPI(Protocol):
142+
def __dataframe_consortium_standard__(
143+
self, *, api_version: str | None = None
144+
) -> DataFrame:
145+
...
146+
147+
51148
__all__ = [
52149
"Any",
53150
"DataFrame",
@@ -65,5 +162,4 @@ def __len__(self, /) -> int:
65162
"device",
66163
"DType",
67164
"ellipsis",
68-
"Enum",
69165
]

spec/API_specification/dataframe_api/dataframe_object.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .column_object import Column
88
from .groupby_object import GroupBy
99
from . import Bool
10-
from ._types import NullType, Scalar
10+
from ._types import NullType, Scalar, Namespace
1111

1212

1313
__all__ = ["DataFrame"]
@@ -37,7 +37,7 @@ class DataFrame:
3737
**Methods and Attributes**
3838
3939
"""
40-
def __dataframe_namespace__(self) -> Any:
40+
def __dataframe_namespace__(self) -> Namespace:
4141
"""
4242
Returns an object that has all the top-level dataframe API functions on it.
4343

0 commit comments

Comments
 (0)