question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix errors when entering a value for a cell larger than the max int in Array and Dataframe editors

See original GitHub issue

Description

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?

  1. Create a pandas DataFrame of type int32 or int64 (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)
  1. Open the dataframe or array from Variable Explorer in a DataFrame/Array Editor
  2. Paste in a value larger than the data type can hold, e.g. 17179869184 for int32 or 73786976294838206464 for int64, 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:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ccordoba12commented, Jan 4, 2018

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.

0reactions
CAM-Gerlachcommented, Jan 4, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Input contains NaN, infinity or a value too large for dtype ...
I have built an input matrix and I keep getting the following error. ValueError: Input contains NaN, infinity or a value too large...
Read more >
Handling Missing Data | Python Data Science Handbook
We cannot drop single values from a DataFrame ; we can only drop full rows or full columns. Depending on the application, you...
Read more >
Essential basic functionality — pandas 1.5.2 documentation
Missing data / operations with fill values#. In Series and DataFrame, the arithmetic functions have the option of inputting a fill_value, namely a...
Read more >
How to iterate over rows in Pandas: Most efficient options
This error occurs because each item in our iterrows() generator is a tuple-type object with two values, the row index and the row...
Read more >
Find maximum values & position in columns and rows of a ...
For the maximum value of each row, call the max() method on the Dataframe object with an argument axis=1. In the output, we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found