Skip to content

cartesian: improve errors when accessing fields with float literals / expressions #2203

@romanc

Description

@romanc

Description

We got a false positive user report, which tracked down to the usage of float literals/expression in field offsets. Field offsets are expected to be of integer type. All eve nodes support datamodel validation. We could thus implement consistent checks for all field offsets (CartesianOffset, VariableKOffset) to either be an integer literal or evaluate to an integer expression.

Currently, we have such a datamodel validator for the "K" offset of VariableKOffset

class CartesianOffset(eve.Node):
i: int
j: int
k: int
@classmethod
def zero(cls) -> CartesianOffset:
return cls(i=0, j=0, k=0)
def to_dict(self) -> Dict[str, int]:
return {"i": self.i, "j": self.j, "k": self.k}
class VariableKOffset(eve.GenericNode, Generic[ExprT]):
k: ExprT
def to_dict(self) -> Dict[str, Optional[int]]:
return {"i": 0, "j": 0, "k": None}
@datamodels.validator("k")
def offset_expr_is_int(self, attribute: datamodels.Attribute, value: Any) -> None:
value = typing.cast(Expr, value)
if value.dtype is not DataType.AUTO and not value.dtype.isinteger():
raise ValueError("Variable vertical index must be an integer expression")

This PR suggests to use a similar validator for the members of CartesianOffset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gt4py.cartesianIssues concerning the current version with support only for cartesian grids.module: backendRelated to analysis/backend subpackagespriority: lowLow priority tasktriage: enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions