Skip to content

Commit 76ad5b0

Browse files
authored
sort out null (#320)
1 parent 987c12b commit 76ad5b0

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
Scalar = Any
2424
# null is a special object which represents a missing value.
2525
# It is not valid as a type.
26-
NullType = Any
2726

2827

2928
class Namespace(Protocol):
@@ -65,6 +64,11 @@ class Bool:
6564
class Date:
6665
...
6766

67+
class NullType:
68+
...
69+
70+
null: NullType
71+
6872
class Datetime:
6973
def __init__( # noqa: ANN204
7074
self,
@@ -127,6 +131,7 @@ def date(self, year: int, month: int, day: int) -> Scalar:
127131
...
128132

129133

134+
NullType = Namespace.NullType
130135
DType = Union[
131136
Namespace.Bool,
132137
Namespace.Float64,
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)