TypeError when using multiple pens for different lines#2704
TypeError when using multiple pens for different lines#2704j9ac9k merged 2 commits intopyqtgraph:masterfrom
Conversation
comparison with None will always cause ``` if np.any(pen != lastPen): TypeError: Cannot compare structured or void to non-void arrays. ``` This does not really follow DRY principle but was the best solution I could come up with using static types in structured array
|
How about: if lastPen is None or np.any(pen != lastPen): |
This is obviously the more elegant solution 😅 |
|
This LGTM, thanks for the PR @adrianlubitz and thanks for the review/feedback @pijyoi |
|
Looking at the code, I don't think that passing in red,green,blue,alpha,width as a numpy record array to specify the pens seems a good idea. (It's also possible to pass in a regular numpy array to specify r,g,b,a, but that's not documented in the docstring) I would think a more useful input parameter would be a Python Prior to this PR, use of multiple pens wouldn't have worked anyway. Would it be a good opportunity to fix the api now? |
Now is always better than later. |
Now I am puzzled. https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/examples/GraphItem.py specifies multiple pens and does work on 0.13.3. So what was this PR fixing? In [40]: lines = np.array([
...: (255,0,0,255,1),
...: (255,0,255,255,2),
...: (255,0,255,255,3),
...: (255,255,0,255,2),
...: (255,0,0,255,1),
...: (255,255,255,255,4),
...: ], dtype=[('red',np.ubyte),('green',np.ubyte),('blue',np.ubyte),('alpha',np.ubyte),('width',float)])
In [41]: lines[4] == None
Out[41]: False
In [42]: lines[4] != None
Out[42]: True
In [43]: np.any(lines[4] != None)
Out[43]: True |
Hi @pijyoi, lines = np.array([
np.array([(255, 0, 0, 255, 1)], dtype=[
('red', np.ubyte), ('green', np.ubyte), ('blue', np.ubyte), ('alpha', np.ubyte), ('width', float)]),
np.array([(255, 0, 255, 255, 2)], dtype=[
('red', np.ubyte), ('green', np.ubyte), ('blue', np.ubyte), ('alpha', np.ubyte), ('width', float)]),
np.array([(255, 0, 255, 255, 3)], dtype=[
('red', np.ubyte), ('green', np.ubyte), ('blue', np.ubyte), ('alpha', np.ubyte), ('width', float)]),
np.array([(255, 255, 0, 255, 2)], dtype=[
('red', np.ubyte), ('green', np.ubyte), ('blue', np.ubyte), ('alpha', np.ubyte), ('width', float)]),
np.array([(255, 0, 0, 255, 1)], dtype=[
('red', np.ubyte), ('green', np.ubyte), ('blue', np.ubyte), ('alpha', np.ubyte), ('width', float)]),
np.array([(255, 255, 255, 255, 4)], dtype=[
('red', np.ubyte), ('green', np.ubyte), ('blue', np.ubyte), ('alpha', np.ubyte), ('width', float)]),
])With the solution from the the PR nested arrays work as well and additionally I could fix my issue and can use pyqtgraph 0.13.3 as dependency. Thanks 😄 |
comparison with None will always cause
This does not really follow DRY principle but was the best solution I could come up with using static types in structured array
Detail the reasoning behind the code change. If there is an associated issue that this PR will resolve add
Fixes #
Other Tasks
Bump Dependency Versions
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