Skip to content

Make typing public #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/API_specification/dataframe_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .dtypes import *

if TYPE_CHECKING:
from ._types import DType
from .typing import DType

__all__ = [
"__dataframe_api_version__",
Expand Down
2 changes: 1 addition & 1 deletion spec/API_specification/dataframe_api/column_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any,NoReturn, TYPE_CHECKING, Literal, Generic

if TYPE_CHECKING:
from ._types import NullType, Scalar, DType, Namespace
from .typing import NullType, Scalar, DType, Namespace


__all__ = ['Column']
Expand Down
2 changes: 1 addition & 1 deletion spec/API_specification/dataframe_api/dataframe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if TYPE_CHECKING:
from .column_object import Column
from .groupby_object import GroupBy
from ._types import NullType, Scalar, Namespace, DType
from .typing import NullType, Scalar, Namespace, DType


__all__ = ["DataFrame"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
from typing import (
TYPE_CHECKING,
Any,
List,
Literal,
Mapping,
Optional,
Protocol,
Sequence,
Tuple,
Union,
)

if TYPE_CHECKING:
from .dataframe_object import DataFrame as DataFrameType
from .column_object import Column as ColumnType
from dataframe_api.column_object import Column
from dataframe_api.dataframe_object import DataFrame
from dataframe_api.groupby_object import GroupBy

if TYPE_CHECKING:
from .dtypes import (
Expand Down Expand Up @@ -51,14 +48,6 @@
class Namespace(Protocol):
__dataframe_api_version__: str

@staticmethod
def DataFrame() -> DataFrameType:
...

@staticmethod
def Column() -> ColumnType:
...

@staticmethod
def Int64() -> Int64:
...
Expand Down Expand Up @@ -116,7 +105,7 @@ def String() -> String:
...

@staticmethod
def concat(dataframes: Sequence[DataFrameType]) -> DataFrameType:
def concat(dataframes: Sequence[DataFrame]) -> DataFrame:
...

@staticmethod
Expand All @@ -126,19 +115,19 @@ def column_from_sequence(
dtype: Any,
name: str = "",
api_version: str | None = None,
) -> ColumnType:
) -> Column:
...

@staticmethod
def dataframe_from_dict(
data: Mapping[str, ColumnType], *, api_version: str | None = None
) -> DataFrameType:
data: Mapping[str, Column], *, api_version: str | None = None
) -> DataFrame:
...

@staticmethod
def column_from_1d_array(
array: Any, *, dtype: Any, name: str = "", api_version: str | None = None
) -> ColumnType:
) -> Column:
...

@staticmethod
Expand All @@ -148,7 +137,7 @@ def dataframe_from_2d_array(
names: Sequence[str],
dtypes: Mapping[str, Any],
api_version: str | None = None,
) -> DataFrameType:
) -> DataFrame:
...

@staticmethod
Expand All @@ -163,31 +152,25 @@ def is_dtype(dtype: Any, kind: str | tuple[str, ...]) -> bool:
class SupportsDataFrameAPI(Protocol):
def __dataframe_consortium_standard__(
self, *, api_version: str | None = None
) -> DataFrameType:
) -> DataFrame:
...

class SupportsColumnAPI(Protocol):
def __column_consortium_standard__(
self, *, api_version: str | None = None
) -> ColumnType:
) -> Column:
...


__all__ = [
"Any",
"Column",
"DataFrame",
"List",
"Literal",
"NestedSequence",
"Optional",
"PyCapsule",
"SupportsBufferProtocol",
"SupportsDLPack",
"Tuple",
"Union",
"Sequence",
"array",
"device",
"DType",
"ellipsis",
"GroupBy",
"Namespace",
"NullType",
"Scalar",
"SupportsColumnAPI",
"SupportsDataFrameAPI",
"Scalar",
]
7 changes: 5 additions & 2 deletions spec/API_specification/examples/01_standardise_columns.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Any
from __future__ import annotations

from dataframe_api._types import SupportsDataFrameAPI
from typing import Any, TYPE_CHECKING

if TYPE_CHECKING:
from dataframe_api.typing import SupportsDataFrameAPI

def my_dataframe_agnostic_function(df_non_standard: SupportsDataFrameAPI) -> Any:
df = df_non_standard.__dataframe_consortium_standard__(api_version='2023.09-beta')
Expand Down
9 changes: 7 additions & 2 deletions spec/API_specification/examples/02_plotting.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from typing import Callable, Any
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from dataframe_api.typing import SupportsColumnAPI
from typing import Callable, Any

my_plotting_function: Callable[[Any, Any], Any]

from dataframe_api._types import SupportsColumnAPI

def group_by_and_plot(
x_any: SupportsColumnAPI,
Expand Down