Skip to content

Commit 15eda61

Browse files
Add null object, and update top-level API specification (data-apis#157)
* Add `null` object, and update top-level API specification * Address review comments on singleton and duck typing `null` * Add a free `isnull` function to the top-level namespace * fix _eq__ typo * Change `isnull` type annotation to `object` --------- Co-authored-by: Marco Edward Gorelli <[email protected]>
1 parent 16aabbf commit 15eda61

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

spec/API_specification/dataframe_api/__init__.py

+49-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
from __future__ import annotations
55

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

88
from .column_object import *
99
from .dataframe_object import *
@@ -14,8 +14,9 @@
1414

1515
__dataframe_api_version__: str = "YYYY.MM"
1616
"""
17-
String representing the version of the DataFrame API specification to which the
18-
conforming implementation adheres.
17+
String representing the version of the DataFrame API specification to which
18+
the conforming implementation adheres. Set to a concrete value for a stable
19+
implementation of the dataframe API standard.
1920
"""
2021

2122
def concat(dataframes: Sequence[DataFrame]) -> DataFrame:
@@ -73,3 +74,48 @@ def dataframe_from_dict(data: Mapping[str, Column]) -> DataFrame:
7374
DataFrame
7475
"""
7576
...
77+
78+
class null:
79+
"""
80+
A `null` object to represent missing data.
81+
82+
``null`` is a scalar, and may be used when constructing a `Column` from a
83+
Python sequence with `column_from_sequence`. It does not support ``is``,
84+
``==`` or ``bool``.
85+
86+
Raises
87+
------
88+
TypeError
89+
From ``__eq__`` and from ``__bool__``.
90+
91+
For ``__eq__``: a missing value must not be compared for equality
92+
directly. Instead, use `DataFrame.isnull` or `Column.isnull` to check
93+
for presence of missing values.
94+
95+
For ``__bool__``: truthiness of a missing value is ambiguous.
96+
97+
Notes
98+
-----
99+
Like for Python scalars, the ``null`` object may be duck typed so it can
100+
reside on (e.g.) a GPU. Hence, the builtin ``is`` keyword should not be
101+
used to check if an object *is* the ``null`` object.
102+
103+
"""
104+
...
105+
106+
def isnull(value: object, /) -> bool:
107+
"""
108+
Check if an object is a `null` scalar.
109+
110+
Parameters
111+
----------
112+
value : object
113+
Any input type is valid.
114+
115+
Returns
116+
-------
117+
bool
118+
True if the input is a `null` object from the same library which
119+
implements the dataframe API standard, False otherwise.
120+
121+
"""

spec/API_specification/index.rst

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ API specification
55

66
.. currentmodule:: dataframe_api
77

8+
The API consists of dataframe, column and groupby classes, plus a small number
9+
of objects and functions in the top-level namespace. The latter are:
10+
11+
.. autosummary::
12+
:toctree: generated
13+
:template: attribute.rst
14+
:nosignatures:
15+
16+
__dataframe_api_version__
17+
isnull
18+
null
19+
20+
The ``DataFrame``, ``Column`` and ``GroupBy`` objects have the following
21+
methods and attributes:
22+
823
.. toctree::
924
:maxdepth: 3
1025

0 commit comments

Comments
 (0)