Skip to content

Commit

Permalink
Variable Explorer: Fix error when viewing DataFrame with no rows
Browse files Browse the repository at this point in the history
Fixes #2791
  • Loading branch information
ccordoba12 committed Nov 16, 2015
1 parent ba5c735 commit 336a8fc
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spyderlib/widgets/dataframeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def __init__(self, dataFrame, format="%.3g", parent=None):

def max_min_col_update(self):
"""Determines the maximum and minimum number in each column"""
# If there are no rows to compute max/min then return
if self.df.shape[0] == 0:
return

This comment has been minimized.

Copy link
@goanpeca

goanpeca Nov 16, 2015

Member

Now that I see this,

Should we have some style guide to avoid having returns in the middle of a method?

I know sometimes it is maybe the best choice, but in general I think having multiple forks inside a method do not help with readability. In these cases either the method is too large and has to be decomposed in smaller routines or, the result should be captured in a variable and returned at the end of the method.

In this particular case is weird that we return to escape a method that actually does not return anything by default. An if wrapping the whole functionality or just the part that makes the max_r and min_r calculations....

Food for thought...

max_r = self.df.max(numeric_only=True)
min_r = self.df.min(numeric_only=True)
self.max_min_col = list(zip(max_r, min_r))
Expand Down

0 comments on commit 336a8fc

Please sign in to comment.