Raise appropriate Exceptions in place of generic exceptions#2474
Raise appropriate Exceptions in place of generic exceptions#2474j9ac9k merged 4 commits intopyqtgraph:masterfrom
Conversation
| return 'Nx2array' | ||
| else: | ||
| raise Exception('array shape must be (N,) or (N,2); got %s instead' % str(obj.shape)) | ||
| raise ArrayDimensionError('array shape must be (N,) or (N,2); got %s instead' % str(obj.shape)) |
There was a problem hiding this comment.
I do think it's a good idea to introduce more specific exceptions for this sort of thing, but I think for this purpose, we should probably stick with ValueError which I believe is what numpy raises when you get a dimension mismatch related exceptions.
There was a problem hiding this comment.
Thank you for the review @j9ac9k , will update it to ValueError.
|
Hi @Nibba2018 Thanks for the PR! I made a comment, while I think it's a good idea to have more specific exceptions, this is something that users of pyqtgraph aren't expecting, so it would create some problems for folks trying to catch this type of exception (they wouldn't know where to import it from). I think what would be best to stick w/ numpy's convention, where I believe they raise a |
| return 'Nx2array' | ||
| else: | ||
| raise Exception('array shape must be (N,) or (N,2); got %s instead' % str(obj.shape)) | ||
| raise TypeError('array shape must be (N,) or (N,2); got %s instead' % str(obj.shape)) |
There was a problem hiding this comment.
Hi, this one should be a ValueError not a TypeError 👍🏻
There was a problem hiding this comment.
OMG sorry about that 🤣
|
diff doesn't match the comment/message, looks like it was replaced with a TypeError ;) |
|
LGTM thanks for the contribution @Nibba2018 ! |
Fixes #2167
Raise
TypeErrorin place of genericExceptionforPlotDataItem.setData().Introduced and raised a new exception named
ArrayDimensionErrorwhen numpy arrays have an Invalid shape.Other Tasks
Raise `TypeError` in place of generic `Exception` for `PlotDataItem.setData()`
Files that need updates
Confirm the following files have been either updated or there has been a determination that no update is needed.
README.mdsetup.pytox.ini.github/workflows/main.ymland associatedrequirements.txtand condaenvironemt.ymlfilespyproject.tomlbinder/requirements.txtPre-Release Checklist
Pre Release Checklist
__init__.pyCHANGELOGprimarily using contents from automated changelog generation in GitHub release pagePost-Release Checklist
Steps To Complete
.dev0to__version__in__init__.py