-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clearer error messages when write() is called with incorrectly formatted channels #411
base: master
Are you sure you want to change the base?
Conversation
Tests Mono/interleaved when stereo expected:
Output
Gave data in row-order rather than column-order (or other way around? idk)
Output:
Channel count was bad to begin with:
output:
If it's confusing that parenthesis are used for both the shape and the note afterward, I could change the parenthetical from round to square brackets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new error messages look good, that's a great improvement.
But the code logic is incorrect, I believe. It should follow the original logic.
soundfile.py
Outdated
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 self.channels not in (1,2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong. Previously, we were checking if the input array had one or two dimensions. Now we're checking whether we have one or two channels. Those are different things, right?
We support arbitrary numbers of channels (depending on the file type), but only one- or two-dimensional data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misunderstood what the old code was doing but I see the problem now. Will fix
With corrections, new tests
Output: Successfully writes 4-channel file
Output:
Output:
If I change channels= to 1, this successfully writes a 1-channel file. It appears something earlier in the code is converting scalars (0-dimensional arrays) to 1-dimensional arrays. This is an okay behavior, and I recommend leaving the check in _array_io as submitted so the code works standalone. |
Thank you very much! The error messages are indeed much improved! Is this ready to merge from your end? |
Yes. |
Wait, why is |
Resolves issue #404