Skip to content

Commit 2de69ca

Browse files
committed
remove unused typevars, make dtype type alias
1 parent a40a6ad commit 2de69ca

File tree

4 files changed

+90
-136
lines changed

4 files changed

+90
-136
lines changed

spec/API_specification/dataframe_api/__init__.py

+10-45
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
"""
44
from __future__ import annotations
55

6-
from typing import Mapping, Sequence, Any
6+
from typing import Mapping, Sequence, Any, TYPE_CHECKING
77

88
from .column_object import *
99
from .dataframe_object import DataFrame
1010
from .groupby_object import *
11-
from ._types import DType
11+
from .dtypes import *
12+
13+
if TYPE_CHECKING:
14+
from ._types import DType
1215

1316
__all__ = [
1417
"__dataframe_api_version__",
@@ -63,7 +66,7 @@ def concat(dataframes: Sequence[DataFrame]) -> DataFrame:
6366
"""
6467
...
6568

66-
def column_from_sequence(sequence: Sequence[Any], *, dtype: Any, name: str = '', api_version: str | None = None) -> Column[Any]:
69+
def column_from_sequence(sequence: Sequence[Any], *, dtype: DType, name: str = '', api_version: str | None = None) -> Column:
6770
"""
6871
Construct Column from sequence of elements.
6972
@@ -91,7 +94,7 @@ def column_from_sequence(sequence: Sequence[Any], *, dtype: Any, name: str = '',
9194
"""
9295
...
9396

94-
def dataframe_from_dict(data: Mapping[str, Column[Any]], *, api_version: str | None = None) -> DataFrame:
97+
def dataframe_from_dict(data: Mapping[str, Column], *, api_version: str | None = None) -> DataFrame:
9598
"""
9699
Construct DataFrame from map of column names to Columns.
97100
@@ -123,7 +126,7 @@ def dataframe_from_dict(data: Mapping[str, Column[Any]], *, api_version: str | N
123126
...
124127

125128

126-
def column_from_1d_array(array: Any, *, dtype: Any, name: str = '', api_version: str | None = None) -> Column[Any]:
129+
def column_from_1d_array(array: Any, *, dtype: DType, name: str = '', api_version: str | None = None) -> Column:
127130
"""
128131
Construct Column from 1D array.
129132
@@ -232,51 +235,13 @@ def is_null(value: object, /) -> bool:
232235
233236
"""
234237

235-
##########
236-
# Dtypes #
237-
##########
238-
239-
class Int64:
240-
"""Integer type with 64 bits of precision."""
241-
242-
class Int32:
243-
"""Integer type with 32 bits of precision."""
244-
245-
class Int16:
246-
"""Integer type with 16 bits of precision."""
247-
248-
class Int8:
249-
"""Integer type with 8 bits of precision."""
250-
251-
class UInt64:
252-
"""Unsigned integer type with 64 bits of precision."""
253-
254-
class UInt32:
255-
"""Unsigned integer type with 32 bits of precision."""
256-
257-
class UInt16:
258-
"""Unsigned integer type with 16 bits of precision."""
259-
260-
class UInt8:
261-
"""Unsigned integer type with 8 bits of precision."""
262-
263-
class Float64:
264-
"""Floating point type with 64 bits of precision."""
265-
266-
class Float32:
267-
"""Floating point type with 32 bits of precision."""
268-
269-
class Bool:
270-
"""Boolean type with 8 bits of precision."""
271-
272-
273-
def is_dtype(dtype: Any, kind: str | tuple[str, ...]) -> bool:
238+
def is_dtype(dtype: DType, kind: str | tuple[str, ...]) -> bool:
274239
"""
275240
Returns a boolean indicating whether a provided dtype is of a specified data type “kind”.
276241
277242
Parameters
278243
----------
279-
dtype: Any
244+
dtype: DType
280245
The input dtype.
281246
kind: str
282247
data type kind.

spec/API_specification/dataframe_api/_types.py

+18-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
"""
22
Types for type annotations used in the dataframe API standard.
3-
4-
The type variables should be replaced with the actual types for a given
5-
library, e.g., for Pandas TypeVar('DataFrame') would be replaced with pd.DataFrame.
63
"""
74
from __future__ import annotations
85

@@ -14,39 +11,35 @@
1411
Optional,
1512
Sequence,
1613
Tuple,
17-
TypeVar,
1814
Union,
19-
Protocol,
15+
TYPE_CHECKING,
2016
)
2117
from enum import Enum
2218

19+
if TYPE_CHECKING:
20+
from .dtypes import (
21+
Bool,
22+
Float64,
23+
Float32,
24+
Int64,
25+
Int32,
26+
Int16,
27+
Int8,
28+
UInt64,
29+
UInt32,
30+
UInt16,
31+
UInt8,
32+
)
33+
34+
DType = Union[Bool, Float64, Float32, Int64, Int32, Int16, Int8, UInt64, UInt32, UInt16, UInt8]
35+
2336
# Type alias: Mypy needs Any, but for readability we need to make clear this
2437
# is a Python scalar (i.e., an instance of `bool`, `int`, `float`, `str`, etc.)
2538
Scalar = Any
2639
# null is a special object which represents a missing value.
2740
# It is not valid as a type.
2841
NullType = Any
2942

30-
array = TypeVar("array")
31-
device = TypeVar("device")
32-
DType = TypeVar("DType")
33-
SupportsDLPack = TypeVar("SupportsDLPack")
34-
SupportsBufferProtocol = TypeVar("SupportsBufferProtocol")
35-
PyCapsule = TypeVar("PyCapsule")
36-
# ellipsis cannot actually be imported from anywhere, so include a dummy here
37-
# to keep pyflakes happy. https://github.com/python/typeshed/issues/3556
38-
ellipsis = TypeVar("ellipsis")
39-
40-
_T_co = TypeVar("_T_co", covariant=True)
41-
42-
43-
class NestedSequence(Protocol[_T_co]):
44-
def __getitem__(self, key: int, /) -> Union[_T_co, NestedSequence[_T_co]]:
45-
...
46-
47-
def __len__(self, /) -> int:
48-
...
49-
5043

5144
__all__ = [
5245
"Any",

0 commit comments

Comments
 (0)