def _wrap_scalar_conversion(scalar_conversion):
  """Wraps a scalar conversion operator on a named array."""

  def wrapped_scalar_conversion(self: NamedArrayBase):
    if self.named_shape or self.positional_shape:
      raise ValueError(
          "Cannot convert a non-scalar NamedArray or NamedArrayView with"
          f" {scalar_conversion}"
      )
    return scalar_conversion(self.unwrap())

  return wrapped_scalar_conversion
Wraps a scalar conversion operator on a named array.
penzai/core/named_axes.py