From 5de03321a1849471212ea0b010688b0ec3b866e4 Mon Sep 17 00:00:00 2001 From: Derrick Chambers Date: Fri, 24 Jul 2026 09:52:57 +0200 Subject: [PATCH] Fix rank-0 coord select guard and fbe doc typo - coords: _select_by_sample_array used `ndim > 1`, so a rank-0 coord slipped past and crashed on `len()`. Use `ndim != 1`, matching the sibling guards in align_to/get_sample_count/change_length. Add a regression test. - fbe: fix "orginal" typo and the unbalanced paren in the dB docstring formula. --- dascore/core/coords.py | 2 +- dascore/transform/fbe.py | 4 ++-- tests/test_core/test_coords.py | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dascore/core/coords.py b/dascore/core/coords.py index cf1a2636f..e4c23e655 100644 --- a/dascore/core/coords.py +++ b/dascore/core/coords.py @@ -347,7 +347,7 @@ def _select_by_sample_array(self, array): msg = "Using an array input for select with samples requires integer dtype." raise CoordError(msg) # Filter out bad indices - if self.ndim > 1: + if self.ndim != 1: msg = "Select only works on 1D coords." raise CoordError(msg) inds = np.arange(len(self)) diff --git a/dascore/transform/fbe.py b/dascore/transform/fbe.py index 401bfbd34..48ffaf992 100644 --- a/dascore/transform/fbe.py +++ b/dascore/transform/fbe.py @@ -41,8 +41,8 @@ def fbe( can be used for downsampling of the resulting patch. See also [rolling](`dascore.Patch.rolling`) db - Return patch data in decibel [dB] instead of orginal units. - Decibel is calculated as 20 * log10( sqrt(mean(x^2))) ). + Return patch data in decibel [dB] instead of original units. + Decibel is calculated as 20 * log10( sqrt(mean(x^2)) ). **kwargs Used to specify the dimension and asociated frequency, wavelength, or equivalent limits. For example time=(1, 100) applies a time-dimension bandpass diff --git a/tests/test_core/test_coords.py b/tests/test_core/test_coords.py index 9031795c6..7e4a6e956 100644 --- a/tests/test_core/test_coords.py +++ b/tests/test_core/test_coords.py @@ -2104,6 +2104,13 @@ def test_select_sample_array_2d_raises(self, coord_2d): with pytest.raises(CoordError, match="1D coords"): coord_2d.select(np.array([0, 1]), samples=True) + def test_select_sample_array_0d_raises(self): + """A rank-0 coord must also be rejected, not just >1D.""" + coord_0d = CoordPartial(shape=()) + assert coord_0d.ndim == 0 + with pytest.raises(CoordError, match="1D coords"): + coord_0d.select(np.array([0, 1]), samples=True) + def test_get_sample_count_2d_raises(self, coord_2d): """get_sample_count requires a 1D coord.""" with pytest.raises(CoordError, match="1D coords"):