Skip to content

Commit 53f9c76

Browse files
committed
add namespace protocol
1 parent a62fe35 commit 53f9c76

File tree

2 files changed

+103
-5
lines changed

2 files changed

+103
-5
lines changed

spec/API_specification/dataframe_api/_types.py

+100-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
"""
44
from __future__ import annotations
55

6-
from dataclasses import dataclass
76
from typing import (
7+
TYPE_CHECKING,
88
Any,
99
List,
1010
Literal,
11+
Mapping,
1112
Optional,
13+
Protocol,
1214
Sequence,
1315
Tuple,
1416
Union,
1517
TYPE_CHECKING,
1618
)
17-
from enum import Enum
19+
20+
if TYPE_CHECKING:
21+
from .dataframe_object import DataFrame
1822

1923
if TYPE_CHECKING:
2024
from .dtypes import (
@@ -41,6 +45,100 @@
4145
NullType = Any
4246

4347

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

spec/API_specification/dataframe_api/dataframe_object.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
if TYPE_CHECKING:
77
from .column_object import Column
88
from .groupby_object import GroupBy
9-
from ._types import NullType, Scalar, DType
9+
from . import Bool
10+
from ._types import NullType, Scalar, Namespace, DType
1011

1112

1213
__all__ = ["DataFrame"]
@@ -36,7 +37,7 @@ class DataFrame:
3637
**Methods and Attributes**
3738
3839
"""
39-
def __dataframe_namespace__(self) -> Any:
40+
def __dataframe_namespace__(self) -> Namespace:
4041
"""
4142
Returns an object that has all the top-level dataframe API functions on it.
4243

0 commit comments

Comments
 (0)