Skip to content

Commit

Permalink
Variable Explorer: Add a value_to_display entry for Numpy recarrays
Browse files Browse the repository at this point in the history
Fixes #2783

- This avoids freezes with big recarrays
  • Loading branch information
ccordoba12 committed Nov 16, 2015
1 parent 336a8fc commit 2ed3e1c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions spyderlib/widgets/dicteditorutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ class FakeObject(object):

#----Numpy arrays support
try:
from numpy import ndarray
from numpy import array, matrix #@UnusedImport (object eval)
from numpy import ndarray, array, matrix, recarray
from numpy.ma import MaskedArray
except ImportError:
ndarray = array = matrix = MaskedArray = FakeObject # analysis:ignore
ndarray = array = matrix = recarray = MaskedArray = FakeObject # analysis:ignore


def get_numpy_dtype(obj):
Expand Down Expand Up @@ -172,6 +171,9 @@ def unsorted_unique(lista):
#----Display <--> Value
def value_to_display(value, truncate=False, trunc_len=80, minmax=False):
"""Convert value for display purpose"""
if isinstance(value, recarray):
fields = value.names
return 'Field names: ' + ', '.join(fields)
if minmax and isinstance(value, (ndarray, MaskedArray)):

This comment has been minimized.

Copy link
@Nodd

Nodd Nov 16, 2015

Contributor

Maybe use some elif here and afterawrds to gain a bit of responsiveness ?

This comment has been minimized.

Copy link
@ccordoba12

ccordoba12 Nov 16, 2015

Author Member

It's a good idea. I've been using if's because that's what Pierre did before :-)

How much responsiveness do you think we can gain?

This comment has been minimized.

Copy link
@Nodd

Nodd Nov 17, 2015

Contributor

Honnestly I don't know, and I think the only way to know is to profile it. But:

  • It won't hurt
  • I've noticed that spyder is getting slower and slower as more features are added (not complaining about the awesome features!)
  • There were many bug reports where the variable explorer was slowing down script execution. If this function is executed every 2 seconds for every variable in the workspace, it can add up.

That's all I have ! :)

This comment has been minimized.

Copy link
@ccordoba12

ccordoba12 Nov 17, 2015

Author Member

I've noticed that spyder is getting slower and slower as more features are added

A bit worrisome. Besides the bug you reported about scrolling on the Editor, what else have you noticed?

There were many bug reports where the variable explorer was slowing down script execution

I disabled auto-refresh in both Python and IPython consoles because of that, but this code is still run after every execution in an IPython console, so it worth optimizing it. I'll do it for 2.3.8, thanks for the suggestion :-)

This comment has been minimized.

Copy link
@Nodd

Nodd Nov 17, 2015

Contributor

BTW maybe the bug about scrolling can be closed, I don't see it anymore.
Apart from this it's more a feeling rather than actual measurament, but files (even small ones) take around 1 second to open, switching desktops on linux makes spyder refresh the editor and it takes another second. There is also the problem about autocompletion which sometimes creates small freezes.
I'd like to try profiling the repaint function(s), but I don't know how yet.

This comment has been minimized.

Copy link
@ccordoba12

ccordoba12 Nov 19, 2015

Author Member

Please open a new issue about this problems, so we don't forget to address them :-)

if value.size == 0:
return repr(value)
Expand Down

0 comments on commit 2ed3e1c

Please sign in to comment.