diff --git a/src/biocutils/combine.py b/src/biocutils/combine.py index 8f2f5fb..31eb2ff 100644 --- a/src/biocutils/combine.py +++ b/src/biocutils/combine.py @@ -18,7 +18,17 @@ def combine(*x: Any): Returns: A combined object, typically the same type as the first element in ``x``. """ - if hasattr(x[0], "shape") and len(x[0].shape) > 1: + has_1d = False + has_nd = False + for y in x: + if hasattr(y, "shape") and len(y.shape) > 1: + has_nd = True + else: + has_1d = True + + if has_nd and has_1d: + raise ValueError("cannot mix 1-dimensional and higher-dimensional objects in `combine`") + if has_nd: return combine_rows(*x) else: return combine_sequences(*x) diff --git a/tests/test_combine.py b/tests/test_combine.py index 15e1ddf..26faaaa 100644 --- a/tests/test_combine.py +++ b/tests/test_combine.py @@ -36,3 +36,7 @@ def test_basic_mixed_dense_array(): y = np.array([4, 5, 6, 7]).reshape((2,2)) zcomb = combine(x, y) assert zcomb.shape == (4, 2) + + with pytest.raises(ValueError) as ex: + combine(x, [1,2,3,4]) + assert str(ex.value).find("cannot mix") >= 0