MCPcopy Create free account
hub / github.com/apache/arrow / fill_null

Function fill_null

python/pyarrow/compute.py:511–567  ·  view source on GitHub ↗

Replace each null element in values with a corresponding element from fill_value. If fill_value is scalar-like, then every null element in values will be replaced with fill_value. If fill_value is array-like, then the i-th element in values will be replaced with the i-th element

(values, fill_value)

Source from the content-addressed store, hash-verified

509
510
511def fill_null(values, fill_value):
512 """Replace each null element in values with a corresponding
513 element from fill_value.
514
515 If fill_value is scalar-like, then every null element in values
516 will be replaced with fill_value. If fill_value is array-like,
517 then the i-th element in values will be replaced with the i-th
518 element in fill_value.
519
520 The fill_value's type must be the same as that of values, or it
521 must be able to be implicitly casted to the array's type.
522
523 This is an alias for :func:`coalesce`.
524
525 Parameters
526 ----------
527 values : Array, ChunkedArray, or Scalar-like object
528 Each null element is replaced with the corresponding value
529 from fill_value.
530 fill_value : Array, ChunkedArray, or Scalar-like object
531 If not same type as values, will attempt to cast.
532
533 Returns
534 -------
535 result : depends on inputs
536 Values with all null elements replaced
537
538 Examples
539 --------
540 >>> import pyarrow as pa
541 >>> arr = pa.array([1, 2, None, 3], type=pa.int8())
542 >>> fill_value = pa.scalar(5, type=pa.int8())
543 >>> arr.fill_null(fill_value)
544 <pyarrow.lib.Int8Array object at ...>
545 [
546 1,
547 2,
548 5,
549 3
550 ]
551 >>> arr = pa.array([1, 2, None, 4, None])
552 >>> arr.fill_null(pa.array([10, 20, 30, 40, 50]))
553 <pyarrow.lib.Int64Array object at ...>
554 [
555 1,
556 2,
557 30,
558 4,
559 50
560 ]
561 """
562 if not isinstance(fill_value, (pa.Array, pa.ChunkedArray, pa.Scalar)):
563 fill_value = pa.scalar(fill_value, type=values.type)
564 elif values.type != fill_value.type:
565 fill_value = pa.scalar(fill_value.as_py(), type=values.type)
566
567 return call_function("coalesce", [values, fill_value])
568

Callers

nothing calls this directly

Calls 2

as_pyMethod · 0.80
scalarMethod · 0.45

Tested by

no test coverage detected