Skip to content

Commit 7d84cc3

Browse files
committed
Add a fill_null method to dataframe and column
Follow-up to gh-167, which added `fill_nan`, and closes gh-142.
1 parent 62ff4b4 commit 7d84cc3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

spec/API_specification/dataframe_api/column_object.py

+13
Original file line numberDiff line numberDiff line change
@@ -641,3 +641,16 @@ def fill_nan(self, value: float | 'null', /) -> Column:
641641
642642
"""
643643
...
644+
645+
def fill_null(self, value: Scalar, /) -> Column:
646+
"""
647+
Fill null values with the given fill value.
648+
649+
Parameters
650+
----------
651+
value : Scalar
652+
Value used to replace any ``null`` values in the column with.
653+
Must be of the Python scalar type matching the dtype of the column.
654+
655+
"""
656+
...

spec/API_specification/dataframe_api/dataframe_object.py

+33
Original file line numberDiff line numberDiff line change
@@ -774,3 +774,36 @@ def fill_nan(self, value: float | 'null', /) -> DataFrame:
774774
775775
"""
776776
...
777+
778+
def fill_null(
779+
self, value: Scalar, /, *, column_names : list[str] | None = None
780+
) -> DataFrame:
781+
"""
782+
Fill null values with the given fill value.
783+
784+
This method can only be used if all columns that are to be filled are
785+
of the same dtype kind (e.g., all floating-point, all integer, all
786+
string or all datetime dtypes). If that is not the case, it is not
787+
possible to use a single Python scalar type that matches the dtype of
788+
all columns to which ``fill_null`` is being applied, and hence an
789+
exception will be raised.
790+
791+
Parameters
792+
----------
793+
value : Scalar
794+
Value used to replace any ``null`` values in the dataframe with.
795+
Must be of the Python scalar type matching the dtype(s) of the dataframe.
796+
column_names : list[str] | None
797+
A list of column names for which to replace nulls with the given
798+
scalar value.
799+
800+
Raises
801+
------
802+
TypeError
803+
If the columns of the dataframe are not all of the same kind.
804+
KeyError
805+
If ``column_names`` contains a column name that is not present in
806+
the dataframe.
807+
808+
"""
809+
...

0 commit comments

Comments
 (0)