Skip to content

Commit

Permalink
sort out null (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Nov 14, 2023
1 parent 987c12b commit 76ad5b0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion spec/API_specification/dataframe_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ def dataframe_from_2d_array(array: Any, *, schema: dict[str, DType]) -> DataFram
class null: # noqa: N801
"""A `null` object to represent missing data.
Not meant to be instantiated, use ``null`` directly.
``null`` is a scalar, and may be used when constructing a `Column` from a
Python sequence with `column_from_sequence`. It does not support ``is``,
Python sequence with :func:`column_from_sequence`. It does not support ``is``,
``==`` or ``bool``.
Raises
Expand Down
7 changes: 6 additions & 1 deletion spec/API_specification/dataframe_api/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
Scalar = Any
# null is a special object which represents a missing value.
# It is not valid as a type.
NullType = Any


class Namespace(Protocol):
Expand Down Expand Up @@ -65,6 +64,11 @@ class Bool:
class Date:
...

class NullType:
...

null: NullType

class Datetime:
def __init__( # noqa: ANN204
self,
Expand Down Expand Up @@ -127,6 +131,7 @@ def date(self, year: int, month: int, day: int) -> Scalar:
...


NullType = Namespace.NullType
DType = Union[
Namespace.Bool,
Namespace.Float64,
Expand Down
14 changes: 14 additions & 0 deletions spec/API_specification/examples/03_working_with_nulls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Fill a column's NaN values with the implemenation's null value."""
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from dataframe_api.typing import SupportsDataFrameAPI


def main(df_raw: SupportsDataFrameAPI) -> SupportsDataFrameAPI:
df = df_raw.__dataframe_consortium_standard__(api_version="2023-11.beta")
namespace = df.__dataframe_namespace__()
df = df.fill_nan(namespace.null)
return df.dataframe

0 comments on commit 76ad5b0

Please sign in to comment.