Skip to content

Commit

Permalink
Rename CompatibilityError instead of SplitError
Browse files Browse the repository at this point in the history
  • Loading branch information
atrabattoni committed Sep 14, 2024
1 parent 9995383 commit 534eced
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions tests/test_routines.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pytest
from xdas.core.routines import Bag, SplitError
from xdas.core.routines import Bag, CompatibilityError
from xdas.core.dataarray import DataArray
from xdas.core.coordinates import Coordinates

Expand Down Expand Up @@ -49,23 +49,23 @@ def test_bag_append_incompatible_dims(self):
da2 = DataArray(np.random.rand(10, 5), dims=("space", "time"))
bag = Bag(dim="time")
bag.append(da1)
with pytest.raises(SplitError):
with pytest.raises(CompatibilityError):
bag.append(da2)

def test_bag_append_incompatible_shape(self):
da1 = DataArray(np.random.rand(10, 5), dims=("time", "space"))
da2 = DataArray(np.random.rand(10, 6), dims=("time", "space"))
bag = Bag(dim="time")
bag.append(da1)
with pytest.raises(SplitError):
with pytest.raises(CompatibilityError):
bag.append(da2)

def test_bag_append_incompatible_dtype(self):
da1 = DataArray(np.random.rand(10, 5), dims=("time", "space"))
da2 = DataArray(np.random.randint(0, 10, size=(10, 5)), dims=("time", "space"))
bag = Bag(dim="time")
bag.append(da1)
with pytest.raises(SplitError):
with pytest.raises(CompatibilityError):
bag.append(da2)

def test_bag_append_incompatible_coords(self):
Expand All @@ -81,7 +81,7 @@ def test_bag_append_incompatible_coords(self):
)
bag = Bag(dim="time")
bag.append(da1)
with pytest.raises(SplitError):
with pytest.raises(CompatibilityError):
bag.append(da2)

def test_bag_append_incompatible_sampling_interval(self):
Expand All @@ -97,5 +97,5 @@ def test_bag_append_incompatible_sampling_interval(self):
)
bag = Bag(dim="time")
bag.append(da1)
with pytest.raises(SplitError):
with pytest.raises(CompatibilityError):
bag.append(da2)
14 changes: 7 additions & 7 deletions xdas/core/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def combine_by_coords(
for da in objs:
try:
bag.append(da)
except SplitError:
except CompatibilityError:
bags.append(bag)
bag = Bag(dim)
bag.append(da)
Expand All @@ -537,7 +537,7 @@ def combine_by_coords(
return collection


class SplitError(Exception):
class CompatibilityError(Exception):
"""Custom exception to signal required splitting."""

def __init__(self, message):
Expand Down Expand Up @@ -582,16 +582,16 @@ def append(self, da):

def check_dims(self, da):
if not self.dims == da.dims:
raise SplitError("dimensions are not compatible")
raise CompatibilityError("dimensions are not compatible")

def check_shape(self, da):
subshape = tuple(size for dim, size in da.sizes.items() if not dim == self.dim)
if not self.subshape == subshape:
raise SplitError("shapes are not compatible")
raise CompatibilityError("shapes are not compatible")

def check_dtype(self, da):
if not self.dtype == da.dtype:
raise SplitError("data types are not compatible")
raise CompatibilityError("data types are not compatible")

def check_coords(self, da):
subcoords = (
Expand All @@ -600,15 +600,15 @@ def check_coords(self, da):
else da.coords.drop_coords(self.dim)
)
if not self.subcoords.equals(subcoords):
raise SplitError("coordinates are not compatible")
raise CompatibilityError("coordinates are not compatible")

def check_sampling_interval(self, da):
if self.delta is None:
pass
else:
delta = get_sampling_interval(da, self.dim)
if not np.isclose(delta, self.delta):
raise SplitError("sampling intervals are not compatible")
raise CompatibilityError("sampling intervals are not compatible")


def concatenate(objs, dim="first", tolerance=None, virtual=None, verbose=None):
Expand Down

0 comments on commit 534eced

Please sign in to comment.