Skip to content

Update uxarray error types for cases with misleading/confusing types #1622

Description

@Sevans711

While addressing #1556 I noticed a variety of changes I would recommend making to error types being used, to make them correspond more closely to the actual error being reported. For example, when an error is raised because an object was expected to be an xr.DataArray or a dask.Array, but it is not either of those types, the error should be a TypeError, not a ValueError.

Here is an exhaustive list of all such cases, split into two sections. First, recommended changes which would not break backwards compatibility; the recommended type is a subclass of the currently-used type. Second, recommended changes where the recommended type is not a subclass of the currently-used type.

Proposed changes which do break backwards compatibility:

  1. Exception → ValueError in grid.bounds.insert_pt_in_latlonbox: "Longitude point out of range"
  2. Exception → AssertionError or ValueError(?) in grid.bounds.insert_pt_in_latlonbox: "Logic error in longitude box width calculation"
  3. Exception → AttributeError in property Grid.inverse_indices: "Grid is not a subset, therefore no inverse face indices exist"

Proposed changes which do not break backwards compatibility:

  1. ValueError → TypeError in core.aggregation._node_to_face_aggregation and core.aggregation._node_to_edge_aggregation: (error currently has no message, but is raised to indicate: not isinstance(uxda.data, (np.ndarray, da.Array)).)
  2. ValueError → TypeError in UxDataArray.zonal_anomaly: "Invalid value for 'lat'. Must be a tuple (start, end, step) or array-like band edges."
  3. ValueError → TypeError in Grid.from_face_vertices: "Input must be either a list, tuple, or np.ndarray"
  4. ValueError → NotImplementedError in Grid.boundary_node_indices: (error currently has no message, but seems like it is supposed to indicate that construction of boundary_node_indices is not yet implemented.)
  5. TypeError → ValueError in grid.neighbors.KDTree._build_from_nodes: f"Unknown coordinate_system, {self.coordinate_system}, use either 'cartesian' or 'spherical'".
  6. TypeError → ValueError in grid.neighbors.KDTree._current_tree and grid.neighbors.BallTree._current_tree: f"Unknown coordinates location, {self._coordinates}, use either 'nodes', 'face centers', or 'edge centers'"
  7. ValueError → NotImplementedError in grid.slice._slice_node_indices, grid.slice._slice_node_indices, and grid.slice._slice_face_indices: "Exclusive slicing is not yet supported."
  8. ValueError → TypeError in grid.utils.make_setter: f"{key} must be an xr.DataArray" (raised if not isinstance(value, xr.DataArray)).
  9. ValueError → NotImplementedError in io._esmf._read_esmf: "Reading in ESMF grids with Cartesian coordinates not yet supported"
  10. ValueError → NotImplementedError in io._icon._read_icon: "Conversion of the ICON Dual mesh is not yet supported."
  11. Exception → NotImplementedError in io._scrip._to_ugrid: "Structured scrip files are not yet supported"
  12. ValueError → AttributeError in remap.yac._get_lon_lat: f"Grid does not provide {lon_attr}/{lat_attr} required for YAC remapping."

Metadata

Metadata

Assignees

No one assigned

    Labels

    developer experienceMakes the codebase easier to read, debug, maintain, or extend.improvementImprovements on existing features or infrastructure

    Type

    No type

    Projects

    Status
    📚 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions