Skip to content

Commit

Permalink
Merge branch 'mcclure-channel-error'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastian Bechtold committed Dec 30, 2024
2 parents 6195420 + 0812810 commit ed3b9c2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,10 +1379,11 @@ def _check_dtype(self, dtype):

def _array_io(self, action, array, frames):
"""Check array and call low-level IO function."""
if (array.ndim not in (1, 2) or
array.ndim == 1 and self.channels != 1 or
array.ndim == 2 and array.shape[1] != self.channels):
raise ValueError("Invalid shape: {0!r}".format(array.shape))
if array.ndim not in (1,2):
raise ValueError("Invalid shape: {0!r} ({1})".format(array.shape, "0 dimensions not supported" if array.ndim < 1 else "too many dimensions"))
array_channels = 1 if array.ndim == 1 else array.shape[1]
if array_channels != self.channels:
raise ValueError("Invalid shape: {0!r} (Expected {1} channels, got {2})".format(array.shape, self.channels, array_channels))
if not array.flags.c_contiguous:
raise ValueError("Data must be C-contiguous")
ctype = self._check_dtype(array.dtype.name)
Expand Down

0 comments on commit ed3b9c2

Please sign in to comment.