Skip to content

Commit a0f757b

Browse files
authored
Add a fill_null method to dataframe and column (#173)
* Add a `fill_null` method to dataframe and column Follow-up to gh-167, which added `fill_nan`, and closes gh-142. * Address review comments about `DataFrame.fill_null`
1 parent 62ff4b4 commit a0f757b

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-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

+32
Original file line numberDiff line numberDiff line change
@@ -774,3 +774,35 @@ 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 (e.g., all of ``Float64`` or all of string dtype).
786+
If that is not the case, it is not possible to use a single Python
787+
scalar type that matches the dtype of all columns to which
788+
``fill_null`` is being applied, and hence an exception will be raised.
789+
790+
Parameters
791+
----------
792+
value : Scalar
793+
Value used to replace any ``null`` values in the dataframe with.
794+
Must be of the Python scalar type matching the dtype(s) of the dataframe.
795+
column_names : list[str] | None
796+
A list of column names for which to replace nulls with the given
797+
scalar value. If ``None``, nulls will be replaced in all columns.
798+
799+
Raises
800+
------
801+
TypeError
802+
If the columns of the dataframe are not all of the same kind.
803+
KeyError
804+
If ``column_names`` contains a column name that is not present in
805+
the dataframe.
806+
807+
"""
808+
...

0 commit comments

Comments
 (0)