MCPcopy Index your code
hub / github.com/pydata/xarray / ffill

Method ffill

xarray/core/dataarray.py:3685–3767  ·  view source on GitHub ↗

Fill NaN values by propagating values forward *Requires bottleneck.* Parameters ---------- dim : Hashable Specifies the dimension along which to propagate values when filling. limit : int or None, default: None The maximum

(self, dim: Hashable, limit: int | None = None)

Source from the content-addressed store, hash-verified

3683 )
3684
3685 def ffill(self, dim: Hashable, limit: int | None = None) -> Self:
3686 """Fill NaN values by propagating values forward
3687
3688 *Requires bottleneck.*
3689
3690 Parameters
3691 ----------
3692 dim : Hashable
3693 Specifies the dimension along which to propagate values when
3694 filling.
3695 limit : int or None, default: None
3696 The maximum number of consecutive NaN values to forward fill. In
3697 other words, if there is a gap with more than this number of
3698 consecutive NaNs, it will only be partially filled. Must be greater
3699 than 0 or None for no limit. Must be None or greater than or equal
3700 to axis length if filling along chunked axes (dimensions).
3701
3702 Returns
3703 -------
3704 filled : DataArray
3705
3706 Examples
3707 --------
3708 >>> temperature = np.array(
3709 ... [
3710 ... [np.nan, 1, 3],
3711 ... [0, np.nan, 5],
3712 ... [5, np.nan, np.nan],
3713 ... [3, np.nan, np.nan],
3714 ... [0, 2, 0],
3715 ... ]
3716 ... )
3717 >>> da = xr.DataArray(
3718 ... data=temperature,
3719 ... dims=["Y", "X"],
3720 ... coords=dict(
3721 ... lat=("Y", np.array([-20.0, -20.25, -20.50, -20.75, -21.0])),
3722 ... lon=("X", np.array([10.0, 10.25, 10.5])),
3723 ... ),
3724 ... )
3725 >>> da
3726 <xarray.DataArray (Y: 5, X: 3)> Size: 120B
3727 array([[nan, 1., 3.],
3728 [ 0., nan, 5.],
3729 [ 5., nan, nan],
3730 [ 3., nan, nan],
3731 [ 0., 2., 0.]])
3732 Coordinates:
3733 lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0
3734 lon (X) float64 24B 10.0 10.25 10.5
3735 Dimensions without coordinates: Y, X
3736
3737 Fill all NaN values:
3738
3739 >>> da.ffill(dim="Y", limit=None)
3740 <xarray.DataArray (Y: 5, X: 3)> Size: 120B
3741 array([[nan, 1., 3.],
3742 [ 0., 1., 5.],

Callers 5

test_ffillFunction · 0.95
test_ffill_bfill_nonansFunction · 0.95
test_ffill_bfill_allnansFunction · 0.95
test_ffill_limitFunction · 0.95

Calls 1

ffillFunction · 0.90

Tested by 5

test_ffillFunction · 0.76
test_ffill_bfill_nonansFunction · 0.76
test_ffill_bfill_allnansFunction · 0.76
test_ffill_limitFunction · 0.76