Skip to content

Commit 0ef04a2

Browse files
committed
sort out null
1 parent 7be00b6 commit 0ef04a2

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

spec/API_specification/dataframe_api/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,10 @@ def dataframe_from_2d_array(array: Any, *, schema: dict[str, DType]) -> DataFram
197197
class null: # noqa: N801
198198
"""A `null` object to represent missing data.
199199
200+
Not meant to be instantiated, use ``null`` directly.
201+
200202
``null`` is a scalar, and may be used when constructing a `Column` from a
201-
Python sequence with `column_from_sequence`. It does not support ``is``,
203+
Python sequence with :func:`column_from_sequence`. It does not support ``is``,
202204
``==`` or ``bool``.
203205
204206
Raises

spec/API_specification/dataframe_api/typing.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
Scalar = Any
5959
# null is a special object which represents a missing value.
6060
# It is not valid as a type.
61-
NullType = Any
6261

6362

6463
class Namespace(Protocol):
@@ -100,6 +99,11 @@ class Bool:
10099
class Date:
101100
...
102101

102+
class NullType:
103+
...
104+
105+
null: NullType
106+
103107
class Datetime:
104108
def __init__( # noqa: ANN204
105109
self,
@@ -155,6 +159,9 @@ def date(self, year: int, month: int, day: int) -> Scalar:
155159
...
156160

157161

162+
NullType = Namespace.NullType
163+
164+
158165
class SupportsDataFrameAPI(Protocol):
159166
def __dataframe_consortium_standard__(
160167
self,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Fill a column's NaN values with the implemenation's null value."""
2+
from __future__ import annotations
3+
4+
from typing import TYPE_CHECKING
5+
6+
if TYPE_CHECKING:
7+
from dataframe_api.typing import SupportsDataFrameAPI
8+
9+
10+
def main(df_raw: SupportsDataFrameAPI) -> SupportsDataFrameAPI:
11+
df = df_raw.__dataframe_consortium_standard__(api_version="2023-11.beta")
12+
namespace = df.__dataframe_namespace__()
13+
df = df.fill_nan(namespace.null)
14+
return df.dataframe

0 commit comments

Comments
 (0)