Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-795

Improve Integration of Numeric Packages

    XMLWordPrintable

    Details

    • Type: User Story
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.11.0
    • Fix Version/s: 5.13
    • Component/s: PySide, Shiboken
    • Labels:
      None

      Description

      This is a first draft, discussion welcome

      PySide needs to be more user-friendly when interfacing to other packages.

      The most prominent example is NumPy, but it applies to other packages like SciPy, Pandas and MatPlotLib as well.

      After looking into this issue, it appears to be a two-fold problem:

      a) Many types support only List instead of allowing any sequence,

      b) The error messages are extremely misleading and wrong.

      Examples for a):

      There are many locations where PySide accepts a list only, although a sequence would be ok as well. That would allow for many new container types from NumPy, for instance.

      This example says it uses a set, but it does not work:

      >>> QtCore.QItemSelection.fromSet({2, 3, 5})
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: 'PySide2.QtCore.QItemSelection.fromSet' called with wrong argument types:
        PySide2.QtCore.QItemSelection.fromSet(set)
      Supported signatures:
        PySide2.QtCore.QItemSelection.fromSet(QSet)
      >>> 
      

      The same with the function fromVector does of course not allow an arbitrary sequence.

      >>> QtCore.QItemSelection.fromVector([1, 2, 3])
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: 'PySide2.QtCore.QItemSelection.fromVector' called with wrong argument types:
        PySide2.QtCore.QItemSelection.fromVector(list)
      Supported signatures:
        PySide2.QtCore.QItemSelection.fromVector(list)
      >>> 
      

      but gives a very unintuitive error message.

      I propose to either

      • allow arbitrary sequences here, or
      • add a new method fromSequence.

      That would then work with any extension that uses the sequence protocol.

      Examples for b):

      When trying to find negative examples for a), I stumbled surprisingly into examples for b). PySide already supports interfacing to other packages by using abstract protocols.
      See the following example:

      >>> from PySide2 import *
      >>> import numpy as np
      >>> a = np.array((1,2,3,4))
      >>> QtGui.QMatrix2x2(a)
      PySide2.QtGui.QMatrix2x2((1, 2, 3, 4))
      >>> 
      

      Here is the example that gives the impression that NumPy is not supported:

      >>> a3 = np.array((1,2,3))
      >>> QtGui.QMatrix2x2(a3)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: 'PySide2.QtGui.QMatrix2x2' called with wrong argument types:
        PySide2.QtGui.QMatrix2x2(numpy.ndarray)
      Supported signatures:
        PySide2.QtGui.QMatrix2x2(list)
        PySide2.QtGui.QMatrix2x2(PySide2.QtGui.QMatrix2x2)
      >>> 
      

      This problem seems to apply to the matrices, only. The error messages are very wrong, because the general sequence protocol is supported, but it says list. When you look at the file

      exists_{platf}_{version}_ci.py
      

      instead, you see that it says sequence instead. But this is also still not completely correct, since the signature module needs more work on correct types, too.

      First Attempt

      My impression is that before adding a new sequence support that serves many extensions, we should try to

      • improve error messages (re-write them using the signature module)
      • write a tool that checks every function signature for functionality.

      When that is working well enough that we can trust error messages, then we should think of new functionality.

      Maybe the topic of this task needs to be changed?

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              ctismer Christian Tismer
              Reporter:
              ctismer Christian Tismer
              RnD Owner:
              Alex Blasche
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews