Skip to content

Commit d43ecf1

Browse files
committed
Add a fill_null method to dataframe and column
Follow-up to data-apisgh-167, which added `fill_nan`, and closes data-apisgh-142.
1 parent 2950673 commit d43ecf1

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
@@ -470,3 +470,16 @@ def fill_nan(self, value: float | 'null', /) -> Column:
470470
471471
"""
472472
...
473+
474+
def fill_null(self, value: Scalar, /) -> Column:
475+
"""
476+
Fill null values with the given fill value.
477+
478+
Parameters
479+
----------
480+
value : Scalar
481+
Value used to replace any ``null`` values in the column with.
482+
Must be of the Python scalar type matching the dtype of the column.
483+
484+
"""
485+
...

spec/API_specification/dataframe_api/dataframe_object.py

+33
Original file line numberDiff line numberDiff line change
@@ -723,3 +723,36 @@ def fill_nan(self, value: float | 'null', /) -> DataFrame:
723723
724724
"""
725725
...
726+
727+
def fill_null(
728+
self, value: Scalar, /, *, column_names : list[str] | None = None
729+
) -> DataFrame:
730+
"""
731+
Fill null values with the given fill value.
732+
733+
This method can only be used if all columns that are to be filled are
734+
of the same dtype kind (e.g., all floating-point, all integer, all
735+
string or all datetime dtypes). If that is not the case, it is not
736+
possible to use a single Python scalar type that matches the dtype of
737+
all columns to which ``fill_null`` is being applied, and hence an
738+
exception will be raised.
739+
740+
Parameters
741+
----------
742+
value : Scalar
743+
Value used to replace any ``null`` values in the dataframe with.
744+
Must be of the Python scalar type matching the dtype(s) of the dataframe.
745+
column_names : list[str] | None
746+
A list of column names for which to replace nulls with the given
747+
scalar value.
748+
749+
Raises
750+
------
751+
TypeError
752+
If the columns of the dataframe are not all of the same kind.
753+
KeyError
754+
If ``column_names`` contains a column name that is not present in
755+
the dataframe.
756+
757+
"""
758+
...

0 commit comments

Comments
 (0)