pyarrow.compute.replace_with_mask

pyarrow.compute.replace_with_mask(values, mask, replacements, *, memory_pool=None)

Replace items using a mask and replacement values.

Given an array and a Boolean mask (either scalar or of equal length), along with replacement values (either scalar or array), each element of the array for which the corresponding mask element is true will be replaced by the next value from the replacements, or with null if the mask is null. Hence, for replacement arrays, len(replacements) == sum(mask == true).

Parameters
  • values (Array-like) – Argument to compute function

  • mask (Array-like) – Argument to compute function

  • replacements (Array-like) – Argument to compute function

  • memory_pool (pyarrow.MemoryPool, optional) – If not passed, will allocate memory from the default memory pool.