Skip to content

Commit

Permalink
simplify coord snap (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-chambers authored May 16, 2024
1 parent d6d757b commit b76da4b
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions dascore/core/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,15 +962,9 @@ def snap(self):
start, stop = max_v, min_v + step
else:
start, stop = min_v, max_v + step
# get potential output, ensure it is the same length as original
# Get potential output, ensure it is the same length as original.
out = CoordRange(start=start, stop=stop, step=step, units=self.units)
# A hack to deal with those pesky off-by-one errors.
if out.shape != self.shape:
diff = len(self) - len(out)
new_stop = stop + diff * step # increase or decrease coord length
out = out.update(stop=new_stop)
assert len(out) == len(self)
return out
return out.change_length(len(self))

@compose_docstring(doc=BaseCoord.update_limits.__doc__)
def update_limits(self, min=None, max=None, step=None, **kwargs) -> Self:
Expand Down

0 comments on commit b76da4b

Please sign in to comment.