Repository: spyder-ide/spyder

Issue:
Profiling error
## Description
- _What steps will reproduce the problem?_
  1. Run a script with a profiler
- _What is the expected output? What do you see instead?_

I see this in the internal console:

```
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/spyderplugins/widgets/profilergui.py", line 253, in <lambda>
    self.finished(ec, es))
  File "/usr/lib/python2.7/site-packages/spyderplugins/widgets/profilergui.py", line 318, in finished
    self.show_data(justanalyzed=True)
  File "/usr/lib/python2.7/site-packages/spyderplugins/widgets/profilergui.py", line 339, in show_data
    self.datatree.load_data(self.DATAPATH)
  File "/usr/lib/python2.7/site-packages/spyderplugins/widgets/profilergui.py", line 427, in load_data
    map(lambda x: x.calc_callees().stats, stats_indi)
  File "/usr/lib/python2.7/site-packages/spyderplugins/widgets/profilergui.py", line 427, in <lambda>
    map(lambda x: x.calc_callees().stats, stats_indi)
AttributeError: 'NoneType' object has no attribute 'stats'
```
- _Please provide any additional information below_
## Version and main components
- Spyder Version:  3.0.0dev 
- Python Version:  2.7.9
- Qt Version    :  4.8.6, PyQt4 (API v2) 4.11.3 on Linux
## Optional dependencies

pyflakes >=0.5.0:  0.8.1 (OK)
pep8 >=0.6      :  1.6.2 (OK)
pygments >=1.6  :  2.0.2 (OK)
IPython >=3.0   :  3.0.0 (OK)
zmq >=13.0.0    :  14.5.0 (OK)
pandas >=0.13.1 :  0.16.0 (OK)
sphinx >=0.6.6  :  1.2.3 (OK)
psutil >=0.3    :  2.2.1 (OK)
rope >=0.9.2    :  0.10.2 (OK)
jedi >=0.8.1    :  0.8.1 (OK)
matplotlib >=1.0:  1.4.3 (OK)
sympy >=0.7.3   :  0.7.6 (OK)
pylint >=0.25   :  1.4.3 (OK)

Profiling error
## Description
- _What steps will reproduce the problem?_
  1. Run a script with a profiler
- _What is the expected output? What do you see instead?_

I see this in the internal console:

```
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/spyderplugins/widgets/profilergui.py", line 253, in <lambda>
    self.finished(ec, es))
  File "/usr/lib/python2.7/site-packages/spyderplugins/widgets/profilergui.py", line 318, in finished
    self.show_data(justanalyzed=True)
  File "/usr/lib/python2.7/site-packages/spyderplugins/widgets/profilergui.py", line 339, in show_data
    self.datatree.load_data(self.DATAPATH)
  File "/usr/lib/python2.7/site-packages/spyderplugins/widgets/profilergui.py", line 427, in load_data
    map(lambda x: x.calc_callees().stats, stats_indi)
  File "/usr/lib/python2.7/site-packages/spyderplugins/widgets/profilergui.py", line 427, in <lambda>
    map(lambda x: x.calc_callees().stats, stats_indi)
AttributeError: 'NoneType' object has no attribute 'stats'
```
- _Please provide any additional information below_
## Version and main components
- Spyder Version:  3.0.0dev 
- Python Version:  2.7.9
- Qt Version    :  4.8.6, PyQt4 (API v2) 4.11.3 on Linux
## Optional dependencies

pyflakes >=0.5.0:  0.8.1 (OK)
pep8 >=0.6      :  1.6.2 (OK)
pygments >=1.6  :  2.0.2 (OK)
IPython >=3.0   :  3.0.0 (OK)
zmq >=13.0.0    :  14.5.0 (OK)
pandas >=0.13.1 :  0.16.0 (OK)
sphinx >=0.6.6  :  1.2.3 (OK)
psutil >=0.3    :  2.2.1 (OK)
rope >=0.9.2    :  0.10.2 (OK)
jedi >=0.8.1    :  0.8.1 (OK)
matplotlib >=1.0:  1.4.3 (OK)
sympy >=0.7.3   :  0.7.6 (OK)
pylint >=0.25   :  1.4.3 (OK)



Discussion:
@dhoegh, you were the last one to touch our profiler. Could you look at this one?

To add more information: the script runs fine and the error appears before displaying the results.

@dhoegh, you were the last one to touch our profiler. Could you look at this one?

To add more information: the script runs fine and the error appears before displaying the results.


Resolving patch:
diff --git a/spyderplugins/widgets/profilergui.py b/spyderplugins/widgets/profilergui.py
--- a/spyderplugins/widgets/profilergui.py
+++ b/spyderplugins/widgets/profilergui.py
@@ -419,16 +419,15 @@ def initialize_view(self):
     def load_data(self, profdatafile):
         """Load profiler data saved by profile/cProfile module"""
         import pstats
-        self.profdata = pstats.Stats(profdatafile)
         stats_indi = [pstats.Stats(profdatafile),]
+        self.profdata = stats_indi[0]
         
         if self.compare_file is not None:
             stats_indi.append(pstats.Stats(self.compare_file))
-        map(lambda x: x.calc_callees().stats, stats_indi)
-        self.profdata.add(profdatafile+"1")
+        map(lambda x: x.calc_callees(), stats_indi)
         self.profdata.calc_callees()
         self.stats1 = stats_indi
-        self.stats = self.profdata.stats
+        self.stats = stats_indi[0].stats
         
     def compare(self,filename):
         self.hide_diff_cols(False)
@@ -538,7 +537,7 @@ def populate_tree(self, parentItem, children_list):
             child_item.setTextAlignment(1, Qt.AlignRight)
             
             child_item.setData(2, Qt.DisplayRole, cum_time_dif[0])
-            child_item.setTextColor(2, QColor(cum_time_dif[1]))
+            child_item.setForeground(2, QColor(cum_time_dif[1]))
             child_item.setTextAlignment(2, Qt.AlignLeft)
 
             child_item.setToolTip(3, _('Local time in function '\
@@ -548,7 +547,7 @@ def populate_tree(self, parentItem, children_list):
             child_item.setTextAlignment(3, Qt.AlignRight)
             
             child_item.setData(4, Qt.DisplayRole, loc_time_dif[0])
-            child_item.setTextColor(4, QColor(loc_time_dif[1]))
+            child_item.setForeground(4, QColor(loc_time_dif[1]))
             child_item.setTextAlignment(4, Qt.AlignLeft)
 
             child_item.setToolTip(5, _('Total number of calls '\
@@ -558,7 +557,7 @@ def populate_tree(self, parentItem, children_list):
             child_item.setTextAlignment(5, Qt.AlignRight)
             
             child_item.setData(6, Qt.DisplayRole, total_calls_dif[0])
-            child_item.setTextColor(6, QColor(total_calls_dif[1]))
+            child_item.setForeground(6, QColor(total_calls_dif[1]))
             child_item.setTextAlignment(6, Qt.AlignLeft)
 
             child_item.setToolTip(7, _('File:line '\


Test patch: