Skip to content

Commit f12057f

Browse files
authored
Make typing public (#282)
* make dataframe.typing public * simplify
1 parent 080425f commit f12057f

File tree

6 files changed

+34
-43
lines changed

6 files changed

+34
-43
lines changed

spec/API_specification/dataframe_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .dtypes import *
1212

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

1616
__all__ = [
1717
"__dataframe_api_version__",

spec/API_specification/dataframe_api/column_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any,NoReturn, TYPE_CHECKING, Literal, Generic
44

55
if TYPE_CHECKING:
6-
from ._types import NullType, Scalar, DType, Namespace
6+
from .typing import NullType, Scalar, DType, Namespace
77

88

99
__all__ = ['Column']

spec/API_specification/dataframe_api/dataframe_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if TYPE_CHECKING:
77
from .column_object import Column
88
from .groupby_object import GroupBy
9-
from ._types import NullType, Scalar, Namespace, DType
9+
from .typing import NullType, Scalar, Namespace, DType
1010

1111

1212
__all__ = ["DataFrame"]

spec/API_specification/dataframe_api/_types.py renamed to spec/API_specification/dataframe_api/typing.py

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
from typing import (
77
TYPE_CHECKING,
88
Any,
9-
List,
109
Literal,
1110
Mapping,
12-
Optional,
1311
Protocol,
1412
Sequence,
15-
Tuple,
1613
Union,
1714
)
1815

19-
if TYPE_CHECKING:
20-
from .dataframe_object import DataFrame as DataFrameType
21-
from .column_object import Column as ColumnType
16+
from dataframe_api.column_object import Column
17+
from dataframe_api.dataframe_object import DataFrame
18+
from dataframe_api.groupby_object import GroupBy
2219

2320
if TYPE_CHECKING:
2421
from .dtypes import (
@@ -51,14 +48,6 @@
5148
class Namespace(Protocol):
5249
__dataframe_api_version__: str
5350

54-
@staticmethod
55-
def DataFrame() -> DataFrameType:
56-
...
57-
58-
@staticmethod
59-
def Column() -> ColumnType:
60-
...
61-
6251
@staticmethod
6352
def Int64() -> Int64:
6453
...
@@ -116,7 +105,7 @@ def String() -> String:
116105
...
117106

118107
@staticmethod
119-
def concat(dataframes: Sequence[DataFrameType]) -> DataFrameType:
108+
def concat(dataframes: Sequence[DataFrame]) -> DataFrame:
120109
...
121110

122111
@staticmethod
@@ -126,19 +115,19 @@ def column_from_sequence(
126115
dtype: Any,
127116
name: str = "",
128117
api_version: str | None = None,
129-
) -> ColumnType:
118+
) -> Column:
130119
...
131120

132121
@staticmethod
133122
def dataframe_from_dict(
134-
data: Mapping[str, ColumnType], *, api_version: str | None = None
135-
) -> DataFrameType:
123+
data: Mapping[str, Column], *, api_version: str | None = None
124+
) -> DataFrame:
136125
...
137126

138127
@staticmethod
139128
def column_from_1d_array(
140129
array: Any, *, dtype: Any, name: str = "", api_version: str | None = None
141-
) -> ColumnType:
130+
) -> Column:
142131
...
143132

144133
@staticmethod
@@ -148,7 +137,7 @@ def dataframe_from_2d_array(
148137
names: Sequence[str],
149138
dtypes: Mapping[str, Any],
150139
api_version: str | None = None,
151-
) -> DataFrameType:
140+
) -> DataFrame:
152141
...
153142

154143
@staticmethod
@@ -163,31 +152,25 @@ def is_dtype(dtype: Any, kind: str | tuple[str, ...]) -> bool:
163152
class SupportsDataFrameAPI(Protocol):
164153
def __dataframe_consortium_standard__(
165154
self, *, api_version: str | None = None
166-
) -> DataFrameType:
155+
) -> DataFrame:
167156
...
168157

169158
class SupportsColumnAPI(Protocol):
170159
def __column_consortium_standard__(
171160
self, *, api_version: str | None = None
172-
) -> ColumnType:
161+
) -> Column:
173162
...
174163

175164

176165
__all__ = [
177-
"Any",
166+
"Column",
178167
"DataFrame",
179-
"List",
180-
"Literal",
181-
"NestedSequence",
182-
"Optional",
183-
"PyCapsule",
184-
"SupportsBufferProtocol",
185-
"SupportsDLPack",
186-
"Tuple",
187-
"Union",
188-
"Sequence",
189-
"array",
190-
"device",
191168
"DType",
192-
"ellipsis",
169+
"GroupBy",
170+
"Namespace",
171+
"NullType",
172+
"Scalar",
173+
"SupportsColumnAPI",
174+
"SupportsDataFrameAPI",
175+
"Scalar",
193176
]

spec/API_specification/examples/01_standardise_columns.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
from typing import Any
1+
from __future__ import annotations
22

3-
from dataframe_api._types import SupportsDataFrameAPI
3+
from typing import Any, TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
from dataframe_api.typing import SupportsDataFrameAPI
47

58
def my_dataframe_agnostic_function(df_non_standard: SupportsDataFrameAPI) -> Any:
69
df = df_non_standard.__dataframe_consortium_standard__(api_version='2023.09-beta')

spec/API_specification/examples/02_plotting.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
from typing import Callable, Any
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
from dataframe_api.typing import SupportsColumnAPI
7+
from typing import Callable, Any
28

39
my_plotting_function: Callable[[Any, Any], Any]
410

5-
from dataframe_api._types import SupportsColumnAPI
611

712
def group_by_and_plot(
813
x_any: SupportsColumnAPI,

0 commit comments

Comments
 (0)