Fix errors when entering a value for a cell larger than the max int in Array and Dataframe editors
See original GitHub issueDescription
Upon entering/pasting a value into a cell in a dataframe or array editor opened from Variable Explorer that is large enough to cause an overflow of that type, Spyder doesn’t catch the resulting OverflowError
and handle it appropriately, instead displaying an error dialog when the cell is clicked off to commit the value (which is, of course, left unchanged). Additionally, for arrays, something in the exception handling isn’t right, such that this situation crashes the entire program with the standard “Python has stopped working error”…except if SPYDER_DEBUG=3
, in which case the error message is just printed to the shell spyder is started from and everything else proceeds normally.
What steps will reproduce the problem?
- Create a pandas DataFrame of type
int32
orint64
(other integer types aren’t supported at all), e.g. with
import pandas as pd
df = pd.DataFrame([0, 0, 0], dtype=np.int32)
or an array, with e.g.
import numpy as np
test_array = np.array([0, 0, 0], dtype=np.int32)
- Open the dataframe or array from Variable Explorer in a DataFrame/Array Editor
- Paste in a value larger than the data type can hold, e.g.
17179869184
forint32
or73786976294838206464
forint64
, and hit enter or click off.
What is the expected output? What do you see instead?
Expected: No hard crash with arrays, and a popup warning dialog similar to the behavior entering a text string in a float column.
When entering a value too large for the current type (int32) but not larger than 64 bit (int64) in an array:
Traceback (most recent call last):
File "C:\Users\christopher.gerlach\Anaconda3\lib\site-packages\spyder\widgets\variableexplorer\arrayeditor.py", line 318, in setData
self.test_array[0] = val # will raise an Exception eventually
OverflowError: Python int too large to convert to C long
When entering a value greater than an int64 into an int64 cell in an array:
Traceback (most recent call last):
File "C:\Users\christopher.gerlach\Anaconda3\lib\site-packages\spyder\widgets\variableexplorer\arrayeditor.py", line 318, in setData
self.test_array[0] = val # will raise an Exception eventually
OverflowError: int too big to convert
Further, both cases then print the following (followed by a hard crash, “Python has stopped working” etc., except in debug mode (SPYDER_DEBUG=3), where everything seems to work fine other than printing the error to the debug console, and of course not actually updating the array with the new value):
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\christopher.gerlach\Anaconda3\lib\site-packages\spyder\widgets\variableexplorer\arrayeditor.py", line 320, in setData
print(type(e.message)) # spyder: test-skip
AttributeError: 'OverflowError' object has no attribute 'message'
For Dataframes, similar occurs but the error is caught by Spyder before it crashes.
When entering a value too large for the current type (int32) but not larger than 64 bit (int64) in a df:
File "C:\Users\christopher.gerlach\Anaconda3\lib\site-packages\spyder\widgets\variableexplorer\dataframeeditor.py", line 368, in setData
self.df.iloc[row, column-1] = current_value.__class__(val)
OverflowError: Python int too large to convert to C long
When entering a value greater than an int64 into an int64 cell in a df:
File "C:\Users\christopher.gerlach\Anaconda3\lib\site-packages\spyder\widgets\variableexplorer\dataframeeditor.py", line 368, in setData
self.df.iloc[row, column-1] = current_value.__class__(val)
OverflowError: int too big to convert
Please provide any additional information below
Proposed Solution:
First of all, fix the exception handling that allows the application hard crash to occur. Then, catch the error in each case, and generate a popup warning dialog with the error similar to the behavior when entering e.g. a value that cannot be converted to the specified data type, like a text string in a numeric column. Ideally, both this case and the “cannot convert” one mentioned should abort while leaving the user with the edit-mode text field with the value they entered so they can more easily correct it, rather than just kicking them out to non-edit mode, showing the previous value, but this would probably take more work than the current behavior.
Version and main components
- Spyder Version: 3.2.5
- Python Version: 3.6.3
- Qt Versions: 5.6.2, PyQt5 5.6 on Windows
Dependencies
pyflakes >=0.6.0 : 1.6.0 (OK)
pycodestyle >=2.3: 2.3.1 (OK)
pygments >=2.0 : 2.2.0 (OK)
pandas >=0.13.1 : 0.21.1 (OK)
numpy >=1.7 : 1.13.3 (OK)
sphinx >=0.6.6 : 1.6.3 (OK)
rope >=0.9.4 : 0.10.5 (OK)
jedi >=0.9.0 : 0.10.2 (OK)
nbconvert >=4.0 : 5.3.1 (OK)
sympy >=0.7.3 : 1.1.1 (OK)
cython >=0.21 : 0.26.1 (OK)
qtconsole >=4.2.0: 4.3.1 (OK)
IPython >=4.0 : 6.1.0 (OK)
pylint >=0.25 : 1.7.4 (OK)
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
I simplified the title ever further. We can’t have so long titles because they go to our Changelog, which is distributed in our tarballs.
Ah, okay. My titles certainly are an offender there, then—I’ll try to keep them more concise going forward. Thanks for the explanation.