Repository: spyder-ide/spyder

Issue:
Crash with seaborn objects (version 0.12.2) Python 3.10 and QtConsole 5.4.0
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

```python
#With Seaborn version 0.12.2
import seaborn.objects as so
import seaborn as sns

sns.get_dataset_names()
penguins = sns.load_dataset('penguins')

(
    so.Plot(penguins, x="bill_length_mm", y="flipper_length_mm", color='island')
    .add(so.Dot(pointsize=4))    
)
```

### Traceback
```python-traceback
Traceback (most recent call last):
  File "C:\Users\BIOMEC\mambaforge\envs\mienv\lib\site-packages\qtconsole\base_frontend_mixin.py", line 138, in _dispatch
    handler(msg)
  File "C:\Users\BIOMEC\mambaforge\envs\mienv\lib\site-packages\qtconsole\rich_jupyter_widget.py", line 137, in _handle_execute_result
    self._append_png(png, True, metadata=metadata.get('image/png',
  File "C:\Users\BIOMEC\mambaforge\envs\mienv\lib\site-packages\qtconsole\rich_jupyter_widget.py", line 256, in _append_png
    self._append_custom(self._insert_png, png, before_prompt, metadata=metadata)
  File "C:\Users\BIOMEC\mambaforge\envs\mienv\lib\site-packages\qtconsole\console_widget.py", line 1012, in _append_custom
    result = insert(cursor, input, *args, **kwargs)
  File "C:\Users\BIOMEC\mambaforge\envs\mienv\lib\site-packages\qtconsole\rich_jupyter_widget.py", line 369, in _insert_png
    self._insert_img(cursor, png, 'png', metadata=metadata)
  File "C:\Users\BIOMEC\mambaforge\envs\mienv\lib\site-packages\qtconsole\rich_jupyter_widget.py", line 382, in _insert_img
    image = image.scaled(width, height,
TypeError: arguments did not match any overloaded call:
  scaled(self, width: int, height: int, aspectRatioMode: Qt.AspectRatioMode = Qt.IgnoreAspectRatio, transformMode: Qt.TransformationMode = Qt.FastTransformation): argument 1 has unexpected type 'float'
  scaled(self, size: QSize, aspectRatioMode: Qt.AspectRatioMode = Qt.IgnoreAspectRatio, transformMode: Qt.TransformationMode = Qt.FastTransformation): argument 1 has unexpected type 'float'
```

## Versions

* Spyder version: 5.4.2  (conda)
* Python version: 3.10.9 64-bit
* Qt version: 5.15.6
* PyQt5 version: 5.15.7
* Operating System: Windows 10

### Dependencies

```
# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.31.1;<9.0.0       :  8.10.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jellyfish >=0.7               :  0.9.0 (OK)
jsonschema >=3.2.0            :  4.17.3 (OK)
keyring >=17.0.0              :  23.4.0 (OK)
nbconvert >=4.0               :  7.2.9 (OK)
numpydoc >=0.6.0              :  1.5.0 (OK)
paramiko >=2.4.0              :  None (NOK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.9.0 (OK)
pygments >=2.0                :  2.11.2 (OK)
pylint >=2.5.0;<3.0           :  2.16.2 (OK)
pylint_venv >=2.1.1           :  2.3.0 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.7.1;<1.8.0          :  1.7.1 (OK)
pylsp_black >=1.2.0           :  1.2.1 (OK)
qdarkstyle >=3.0.2;<3.1.0     :  3.0.2 (OK)
qstylizer >=0.2.2             :  0.2.2 (OK)
qtawesome >=1.2.1             :  1.2.2 (OK)
qtconsole >=5.4.0;<5.5.0      :  5.4.0 (OK)
qtpy >=2.1.0                  :  2.2.0 (OK)
rtree >=0.9.7                 :  1.0.1 (OK)
setuptools >=49.6.0           :  65.6.3 (OK)
sphinx >=0.6.6                :  5.0.2 (OK)
spyder_kernels >=2.4.2;<2.5.0 :  2.4.2 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.6 (OK)
zmq >=22.1.0                  :  23.2.0 (OK)

# Optional:
cython >=0.21                 :  None (NOK)
matplotlib >=3.0.0            :  3.6.2 (OK)
numpy >=1.7                   :  1.23.5 (OK)
pandas >=1.1.1                :  1.5.2 (OK)
scipy >=0.17.0                :  1.10.1 (OK)
sympy >=0.7.3                 :  None (NOK)
```



Discussion:
Hi @joselvira thank you for the feedback! Seems like the issue is located inside the QtConsole code base. Could you check what happens if you run the code provided inside a standalone QtConsole instance? To launch a QtConsole instance run from a cmd with the env where Spyder is installed activated the following: `jupyter qtconsole`

My guess is that since your env is using Python 3.10 some float to int conversion is not being done inside QtConsole when inserting the image for its `width` and most probably `height` too (which is something that is done automatically with Python < 3.10)
Hi dalthviz, thanks for your prompt reply.
Apparently, you are right with your guess. This is the error in the QtConsole:

Error starting QtConsole

Traceback (most recent call last):
File
"C:\Users ... \envs\mienv\lib\site-packages\qtconsole\base_frontend_mixin.py" line 138, in_dispatch handler(msg)

File
"C:\Users ... \envs\mienv\lib\site-packages\qtconsole\rich_jupyter_widget.py", line 137, in _handle_execute_result self._append_png(png, True, metadata=metadata.get('image/png',

File
"C:\Users ... \envs\mienv\lib\site-packages\qtconsole\rich_jupyter_widget.py", line 256, in _append.png self._append_custom(self._insert_png, png, before_prompt, metadata=metadata)

File
"C:\Users ... \envs\mienv\lib\site-packages\qtconsole\console_widget.py", line 1012, in _append_custom result = insert(cursor, input, *args, **kwargs)

File
"C:\Users ... \envs\mienv\lib\site-packages\qtconsole\rich_jupyter_widget.py", line 369, in _insert_png self._insert_img(cursor, png, 'png', metadata=metadata)

File
"C:\Users ... \envs\mienv\lib\site-packages\qtconsole\rich_jupyter_widget.py", line 382, in _insert_img image = image.scale(width, height,
TypeError: arguments did not match any overloaded call: scaled(self, width: int, height: int, aspectRatioMode: Qt.AspectRatioMode = Qt.IgnoreAspectRatio, transformMode: Qt.TransformationMode = Qt.FastTransformation): argument 1 has unexpected type 'float'
scaled(self, size: QSize, aspectRatioMode:
Qt.AspectRatioMode = Qt.IgnoreAspectRatio, transformMode: Qt.TransformationMode = Qt.FastTransformation): argument 1 has unexpected type 'float'

Should we move this to QtConsole @ccordoba12 ?
Github doesn't allow to move issues across organizations. But we can fix it in Qtconsole and increase our requirement on it here.

Resolving patch:
diff --git a/external-deps/qtconsole/qtconsole/rich_jupyter_widget.py b/external-deps/qtconsole/qtconsole/rich_jupyter_widget.py
--- a/external-deps/qtconsole/qtconsole/rich_jupyter_widget.py
+++ b/external-deps/qtconsole/qtconsole/rich_jupyter_widget.py
@@ -379,13 +379,13 @@ def _insert_img(self, cursor, img, fmt, metadata=None):
             image = QtGui.QImage()
             image.loadFromData(img, fmt.upper())
             if width and height:
-                image = image.scaled(width, height,
+                image = image.scaled(int(width), int(height),
                                      QtCore.Qt.IgnoreAspectRatio,
                                      QtCore.Qt.SmoothTransformation)
             elif width and not height:
-                image = image.scaledToWidth(width, QtCore.Qt.SmoothTransformation)
+                image = image.scaledToWidth(int(width), QtCore.Qt.SmoothTransformation)
             elif height and not width:
-                image = image.scaledToHeight(height, QtCore.Qt.SmoothTransformation)
+                image = image.scaledToHeight(int(height), QtCore.Qt.SmoothTransformation)
         except ValueError:
             self._insert_plain_text(cursor, 'Received invalid %s data.'%fmt)
         else:


Test patch:
diff --git a/external-deps/qtconsole/qtconsole/tests/test_jupyter_widget.py b/external-deps/qtconsole/qtconsole/tests/test_jupyter_widget.py
--- a/external-deps/qtconsole/qtconsole/tests/test_jupyter_widget.py
+++ b/external-deps/qtconsole/qtconsole/tests/test_jupyter_widget.py
@@ -1,13 +1,10 @@
 import unittest
 import sys
-from packaging.version import parse
 
 import pytest
-from qtpy import QT6, QT_VERSION
+from qtpy import QT6
 from qtpy import QtWidgets, QtGui
-from qtpy.QtTest import QTest
 
-from qtconsole.client import QtKernelClient
 from qtconsole.jupyter_widget import JupyterWidget
 
 from . import no_display
@@ -73,35 +70,9 @@ def test_other_output(self):
             'In [2]: '
         ))
 
-        # Check proper syntax highlighting
-        if QT6 and parse(QT_VERSION) >= parse('6.3'):
-            html = (
-                '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n'
-                '<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">\n'
-                'p, li { white-space: pre-wrap; }\n'
-                'hr { height: 1px; border-width: 0; }\n'
-                '</style></head><body style=\" font-family:\'Monospace\'; font-size:9pt; font-weight:400; font-style:normal;\">\n'
-                '<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Header</p>\n'
-                '<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>\n'
-                '<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000080;">[other] In [</span><span style=" font-weight:700; color:#000080;">1</span><span style=" color:#000080;">]:</span> a = 1 + 1</p>\n'
-                '<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000080;">\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0...:</span> b = range(10)</p>\n'
-                '<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>\n'
-                '<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000080;">In [</span><span style=" font-weight:700; color:#000080;">2</span><span style=" color:#000080;">]:</span> </p></body></html>'
-            )
-        elif QT6 and parse(QT_VERSION) < parse('6.3'):
-            html = (
-                '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n'
-                '<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">\n'
-                'p, li { white-space: pre-wrap; }\n'
-                '</style></head><body style=\" font-family:\'Monospace\'; font-size:9pt; font-weight:400; font-style:normal;\">\n'
-                '<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Header</p>\n'
-                '<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>\n'
-                '<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000080;">[other] In [</span><span style=" font-weight:700; color:#000080;">1</span><span style=" color:#000080;">]:</span> a = 1 + 1</p>\n'
-                '<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000080;">\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0...:</span> b = range(10)</p>\n'
-                '<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>\n'
-                '<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000080;">In [</span><span style=" font-weight:700; color:#000080;">2</span><span style=" color:#000080;">]:</span> </p></body></html>'
-            )
-        else:
+        # Check proper syntax highlighting.
+        # This changes with every Qt6 release, that's why we don't test it on it.
+        if not QT6:
             html = (
                 '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n'
                 '<html><head><meta name="qrichtext" content="1" /><style type="text/css">\n'
@@ -115,7 +86,7 @@ def test_other_output(self):
                 '<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#000080;">In [</span><span style=" font-weight:600; color:#000080;">2</span><span style=" color:#000080;">]:</span> </p></body></html>'
             )
         
-        self.assertEqual(document.toHtml(), html)
+            self.assertEqual(document.toHtml(), html)
 
     def test_copy_paste_prompt(self):
         """Test copy/paste removes partial and full prompts."""