@@ -4095,9 +4095,21 @@ def from_grid(
40954095 Interpolation method. Default is 'linear_grid'.
40964096 Currently only 'linear_grid' is supported for grid data.
40974097 extrapolation : str, optional
4098- Extrapolation behavior. Default is 'constant', which clamps to edge values.
4099- 'constant': Use nearest edge value for out-of-bounds points.
4100- 'zero': Return zero for out-of-bounds points.
4098+ Extrapolation behavior. Default is ``'constant'`` which clamps to
4099+ edge values. Supported options are::
4100+
4101+ 'constant'
4102+ Use nearest edge value for out-of-bounds points (clamp).
4103+ 'zero'
4104+ Return zero for out-of-bounds points.
4105+ 'natural'
4106+ Use the interpolator's natural behavior: when the
4107+ underlying ``RegularGridInterpolator`` is created with
4108+ ``fill_value=None`` and ``method='linear'``, this results
4109+ in linear extrapolation based on the edge gradients.
4110+
4111+ If an unsupported extrapolation value is supplied a ``ValueError``
4112+ is raised.
41014113 **kwargs : dict, optional
41024114 Additional arguments passed to the Function constructor.
41034115
@@ -4176,6 +4188,14 @@ def from_grid(
41764188 # Create a new Function instance
41774189 func = cls .__new__ (cls )
41784190
4191+ # Validate extrapolation option for grid-based interpolation
4192+ allowed_extrap = ("constant" , "zero" , "natural" )
4193+ if extrapolation not in allowed_extrap :
4194+ raise ValueError (
4195+ "Unsupported extrapolation for grid interpolation. "
4196+ f"Supported values: { allowed_extrap } "
4197+ )
4198+
41794199 # Store grid-specific data first
41804200 func ._grid_axes = axes
41814201 func ._grid_data = grid_data
0 commit comments