Skip to content

Commit

Permalink
Always check the select bounds type. Adds a short-circuit if the coor…
Browse files Browse the repository at this point in the history
…dinates are empty (and dtype is None), and removes the (redundant) bounds type checking in the private _select method.
  • Loading branch information
jmilloy committed Dec 2, 2019
1 parent 8f2a0aa commit 6b22224
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 15 additions & 3 deletions podpac/core/coordinates/coordinates1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,31 @@ def select(self, bounds, return_indices=False, outer=False):
index or slice for the selected coordinates (only if return_indices=True)
"""

# empty case
if self.dtype is None:
return self._select_empty(return_indices)

if isinstance(bounds, dict):
bounds = bounds.get(self.name)
if bounds is None:
return self._select_full(return_indices)

bounds = make_coord_value(bounds[0]), make_coord_value(bounds[1])

# check type
if not isinstance(bounds[0], self.dtype):
raise TypeError(
"Input bounds do match the coordinates dtype (%s != %s)" % (type(self.bounds[0]), self.dtype)
)
if not isinstance(bounds[1], self.dtype):
raise TypeError(
"Input bounds do match the coordinates dtype (%s != %s)" % (type(self.bounds[1]), self.dtype)
)

my_bounds = self.area_bounds.copy()

# If the bounds are of instance datetime64, then the comparison should happen at the lowest precision
if self.dtype == np.datetime64:
if not isinstance(bounds[0], np.datetime64):
raise TypeError("Input bounds should be of type np.datetime64 when selecting data from:", str(self))

my_bounds, bounds = lower_precision_time_bounds(my_bounds, bounds, outer)

# full
Expand Down
3 changes: 0 additions & 3 deletions podpac/core/coordinates/uniform_coordinates1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,6 @@ def _select(self, bounds, return_indices, outer):

# If the bounds are of instance datetime64, then the comparison should happen at the lowest precision
if self.dtype == np.datetime64:
if not isinstance(bounds[0], np.datetime64):
raise TypeError("Input bounds should be of type np.datetime64 when selecting data from:", str(self))

my_bounds, bounds = lower_precision_time_bounds(my_bounds, bounds, outer)

lo = max(bounds[0], my_bounds[0])
Expand Down

0 comments on commit 6b22224

Please sign in to comment.