riptable.rt_fastarraynumba

Functions

fill_backward(arr[, fill_val, inplace, limit])

Replace NaN and invalid array values by propagating the next encountered valid value

fill_forward(arr[, fill_val, inplace, limit])

Replace NaN and invalid array values by propagating the last encountered valid value

riptable.rt_fastarraynumba.fill_backward(arr, fill_val=None, inplace=False, limit=0)[source]

Replace NaN and invalid array values by propagating the next encountered valid value backward.

Note that this method can be called either as a FastArray method (rt.FastArray.fill_backward()) or a function (rt.fill_backward()) that takes an array or FastArray as input. The function returns either an array or a FastArray, depending on the original input.

Parameters:
  • arr (array) – The array for which the NaN and invalid array values are replaced. If fill_backward() is called as a class method, arr is the FastArray instance. If fill_backward() is called as a function, an array or FastArray must be passed to arr.

  • fill_val (scalar, default None) – The value to use where there is no valid value to propagate backward. If fill_val is not specified, NaN and invalid values aren’t replaced where there is no valid value to propagate backward.

  • inplace (bool, default False) – If False, return a copy of the array. If True, modify original data. This modifies any other views on this object.

  • limit (int, default 0) – The maximium number of consecutive NaN or invalid values to fill. If there is a gap with more than this number of consecutive NaN or invalid values, the gap is only partially filled. If no limit is specified, all consecutive NaN and invalid values are replaced.

Returns:

The FastArray is the same size and have the same dtype as the original input.

Return type:

FastArray

See also

rt_fastarraynumba.fill_forward()

Replace NaN and invalid values with the last valid value.

rt_fastarraynumba.fill_backward()

Replace NaN and invalid values with the next valid value.

rt_fastarray.FastArray.fillna()

Replace NaN and invalid values with a specified value or nearby data.

rt_fastarray.FastArray.replacena()

Replace NaN and invalid values with a specified value.

rt_dataset.Dataset.fillna()

Replace NaN and invalid values with a specified value or nearby data.

rt_categorical.Categorical.fill_backward()

Replace NaN and invalid values with the next valid group value.

rt_groupby.GroupBy.fill_backward()

Replace NaN and invalid values with the next valid group value.

Examples

Use a fill_val to replace values where there’s no valid value to propagate backward:

>>> a = rt.FastArray([0.0, rt.nan, rt.nan, rt.nan, 4.0, rt.nan])
>>> a.fill_backward(fill_val = 0)
FastArray([0., 4., 4., 4., 4., 0.])

Call fill_backward() as a function:

>>> a = rt.FastArray([0.0, rt.nan, rt.nan, rt.nan, 4.0, rt.nan])
>>> rt.fill_backward(a, fill_val = 0)
FastArray([0., 4., 4., 4., 4., 0.])

Replace only the first NaN or invalid value in any consecutive series of NaN or invalid values:

>>> a.fill_backward(limit = 1)
FastArray([ 0., nan, nan,  4.,  4., nan])
riptable.rt_fastarraynumba.fill_forward(arr, fill_val=None, inplace=False, limit=0)[source]

Replace NaN and invalid array values by propagating the last encountered valid value forward.

Note that this method can be called either as a FastArray method (rt.FastArray.fill_forward()) or a function (rt.fill_forward()) that takes an array or FastArray as input. The function returns either an array or a FastArray, depending on the original input.

Parameters:
  • arr (array) – The array for which the NaN and invalid array values are replaced. If fill_forward() is called as a class method, arr is the FastArray instance. If fill_forward() is called as a function, an array or FastArray must be passed to arr.

  • fill_val (scalar, default None) – The value to use where there is no valid value to propagate forward. If fill_val is not specified, NaN and invalid values aren’t replaced where there is no valid value to propagate forward.

  • inplace (bool, default False) – If False, return a copy of the array. If True, modify original data. This modifies any other views on this object.

  • limit (int, default 0) – The maximium number of consecutive NaN or invalid values to fill. If there is a gap with more than this number of consecutive NaN or invalid values, the gap are only partially filled. If no limit is specified, all consecutive NaN and invalid values are replaced.

Returns:

The FastArray are the same size and have the same dtype as the original input.

Return type:

FastArray

See also

rt_fastarraynumba.fill_backward()

Replace NaN and invalid values with the next valid value.

rt_fastarraynumba.fill_forward()

Replace NaN and invalid values with the last valid value.

rt_numpy.fill_forward()

Replace NaN and invalid values with the last valid value.

rt_fastarray.FastArray.fillna()

Replace NaN and invalid values with a specified value or nearby data.

rt_fastarray.FastArray.replacena()

Replace NaN and invalid values with a specified value.

rt_dataset.Dataset.fillna()

Replace NaN and invalid values with a specified value or nearby data.

rt_categorical.Categorical.fill_forward()

Replace NaN and invalid values with the last valid group value.

rt_groupby.GroupBy.fill_forward()

Replace NaN and invalid values with the last valid group value.

Examples

Use a fill_val to replace values where there’s no valid value to propagate forward:

>>> a = rt.FastArray([rt.nan, 1.0, rt.nan, rt.nan, rt.nan, 5.0])
>>> a.fill_forward(fill_val = 0)
FastArray([0., 1., 1., 1., 1., 5.])

Call fill_forward() as a function:

>>> a = rt.FastArray([0.0, rt.nan, rt.nan, rt.nan, 4.0, rt.nan])
>>> rt.fill_forward(a, fill_val = 0)
FastArray([0., 0., 0., 0., 4., 4.])

Replace only the first NaN or invalid value in any consecutive series of NaN or invalid values:

>>> a.fill_forward(limit = 1)
FastArray([ 0.,  0., nan, nan,  4.,  4.])