You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FormWidget fails to get a date or datetime value with PySide2 #18958
matplotlib.backends.qt_editor._formlayout.FormWidget.get() converts values of date and datetime fields into python datetime.date and datetime.datetime objects using toPyDate() and toPyDateTime() methods. These exist only in PyQt5; in PySide2 the corresponding functions are called toPython().
One way to fix this is to patch matplotlib.backends.qt_compat._setup_pyqt5() by adding the following lines under if QT_API == QT_API_PYSIDE2:
Traceback (most recent call last):
File "formwidget.py", line 8, in <module>
values = widget.get()
File "lib\site-packages\matplotlib\backends\qt_editor\_formlayout.py", line 346, in get
value = field.dateTime().toPyDateTime()
AttributeError: 'PySide2.QtCore.QDateTime' object has no attribute 'toPyDateTime'
Expected outcome
No output, especially no tracebacks.
Matplotlib version
Operating system: Windows 10
Matplotlib version: 3.3.0 (the bug seems to be in master too)
However note that _formlayout is explicitly private and not suitable for general consumption; we reserve the right to change the module without notice (for example, given that we don't actually use this feature internally, we could certainly decide to "fix" this by just deleting the whole feature). Consider using the PyPI package (https://pypi.org/project/formlayout/) instead.
OTOH this may be a good opportunity to fix the qt editor's behavior wrt units (currently it doesn't handle them at all...).
Thanks for the prompt answer. The issue actually boils down to the figure options editor: we are using date time values on the x axis extensively but the editor's axis limits shows date times as floats making adjustments difficult. I am monkey patching matplotlib.backends.qt_editor.figureoptions.figure_edit to convert the units to correct input widgets which made me discover the issue at hand. Fixing the editor to handle units correctly would indeed be more 'correct' approach.
Activity
anntzer commentedon Nov 16, 2020
Thanks for the report; I don't think we should be patching the PySide2 API (it is what it is); an alternate solution would be along the lines of
However note that
_formlayoutis explicitly private and not suitable for general consumption; we reserve the right to change the module without notice (for example, given that we don't actually use this feature internally, we could certainly decide to "fix" this by just deleting the whole feature). Consider using the PyPI package (https://pypi.org/project/formlayout/) instead.OTOH this may be a good opportunity to fix the qt editor's behavior wrt units (currently it doesn't handle them at all...).
soininen commentedon Nov 16, 2020
Thanks for the prompt answer. The issue actually boils down to the figure options editor: we are using date time values on the x axis extensively but the editor's axis limits shows date times as floats making adjustments difficult. I am monkey patching
matplotlib.backends.qt_editor.figureoptions.figure_editto convert the units to correct input widgets which made me discover the issue at hand. Fixing the editor to handle units correctly would indeed be more 'correct' approach.soininen commentedon Dec 7, 2020
As discussed above, the real fix for my problem would be to make Qt backend's figure options dialog to handle units properly.