Skip to content

Commit

Permalink
Explicitly error if invalid values
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair committed Nov 21, 2024
1 parent a5a5b5e commit ef38185
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion gwcs/coordinate_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
import abc
from collections import defaultdict
import logging
import numbers
import numpy as np
from dataclasses import dataclass, InitVar

Expand Down Expand Up @@ -526,15 +527,20 @@ def to_high_level_coordinates(self, *values):
Parameters
----------
values : `numbers.Number` or `numpy.ndarray`
values : `numbers.Number`, `numpy.ndarray`, or `~astropy.units.Quantity`
``naxis`` number of coordinates as scalars or arrays.
Returns
-------
high_level_coordinates
One (or more) high level object describing the coordinate.
"""
# We allow Quantity-like objects here which values_to_high_level_objects does not.
values = [v.to_value(unit) if hasattr(v, "to_value") else v for v, unit in zip(values, self.unit)]

if not all([isinstance(v, numbers.Number) or type(v) is np.ndarray for v in values]):
raise TypeError("All values should be a scalar number or a numpy array.")

Check warning on line 543 in gwcs/coordinate_frames.py

View check run for this annotation

Codecov / codecov/patch

gwcs/coordinate_frames.py#L542-L543

Added lines #L542 - L543 were not covered by tests
high_level = values_to_high_level_objects(*values, low_level_wcs=self)
if len(high_level) == 1:
high_level = high_level[0]
Expand Down

0 comments on commit ef38185

Please sign in to comment.