Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnfarrell committed Jun 22, 2018
1 parent d6ce7d2 commit eaf7283
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
30 changes: 20 additions & 10 deletions pandastable/core.py
Expand Up @@ -454,7 +454,8 @@ def set_precision(x, p):
self.rowheader.drawSelectedRows(self.multiplerowlist)
self.drawMultipleRows(self.multiplerowlist)
self.drawMultipleCells()

#if callback is not None:
# callback()
return

def redraw(self, event=None, callback=None):
Expand Down Expand Up @@ -1361,7 +1362,12 @@ def applyColumnFunction(self, evt=None):

func = getattr(np, funcname)
if newcol == '':
newcol = funcname + '(%s)' %(','.join(cols))
if len(cols)>3:
s = ' %s cols' %len(cols)
else:
s = '(%s)' %(','.join(cols))[:20]
newcol = funcname + s

if funcname in ['subtract','divide','mod','remainder','convolve']:
newcol = cols[0]+' '+ funcname +' '+cols[1]
df[newcol] = df[cols[0]].combine(df[cols[1]], func=func)
Expand Down Expand Up @@ -1484,22 +1490,22 @@ def applyStringMethod(self):
funcs = ['','split','strip','lstrip','lower','upper','title','swapcase','len',
'slice','replace','concat']
d = MultipleValDialog(title='Apply Function',
initialvalues=(funcs,',',0,1,'','',0),
initialvalues=(funcs,',',0,1,'','',1),
labels=('Function:',
'Split sep:',
'Slice start:',
'Slice end:',
'Pattern:',
'Replace with:',
'Add as new column(s):'),
'In place:'),
types=('combobox','string','int',
'int','string','string','checkbutton'),
tooltips=(None,'separator for split or concat',
'start index for slice',
'end index for slice',
'characters or regular expression for replace',
'characters to replace with',
'do not replace column'),
'replace column'),
parent = self.parentframe)
if d.result == None:
return
Expand All @@ -1510,7 +1516,7 @@ def applyStringMethod(self):
end = d.results[3]
pat = d.results[4]
repl = d.results[5]
newcol = d.results[6]
inplace = d.results[6]
if func == 'split':
new = df[col].str.split(sep).apply(pd.Series)
new.columns = [col+'_'+str(i) for i in new.columns]
Expand All @@ -1537,9 +1543,13 @@ def applyStringMethod(self):
x = df[col].replace(pat, repl, regex=True)
elif func == 'concat':
x = df[col].str.cat(df[cols[1]].astype(str), sep=sep)
if newcol == 1:
col = col+'_'+func
df[col] = x
if inplace == 0:
newcol = col+'_'+func
else:
newcol = col
df[newcol] = x
if inplace == 0:
self.placeColumn(newcol,col)
self.redraw()
return

Expand Down Expand Up @@ -2253,7 +2263,7 @@ def handle_right_click(self, event):
return

def placeColumn(self, col1, col2):
"""Move col2 next to col1, useful for placing a new column
"""Move col1 next to col2, useful for placing a new column
made from the first one next to it so user can see it easily"""

ind1 = self.model.df.columns.get_loc(col1)
Expand Down
7 changes: 5 additions & 2 deletions pandastable/headers.py
Expand Up @@ -390,8 +390,11 @@ def popupMenu(self, event):
currcol = self.table.currentcol
multicols = self.table.multiplecollist
colnames = list(df.columns[multicols])[:4]
colnames = [str(i)[:30] for i in colnames]
colnames = ','.join(colnames)
colnames = [str(i)[:20] for i in colnames]
if len(colnames)>2:
colnames = ','.join(colnames[:2])+'+%s others' %str(len(colnames)-2)
else:
colnames = ','.join(colnames)
popupmenu = Menu(self, tearoff = 0)
def popupFocusOut(event):
popupmenu.unpost()
Expand Down
9 changes: 5 additions & 4 deletions pandastable/plotting.py
Expand Up @@ -318,7 +318,7 @@ def _checkNumeric(self, df):
"""Get only numeric data that can be plotted"""

#x = df.convert_objects()._get_numeric_data()
x = df.apply( lambda x: pd.to_numeric(x,errors='ignore') )
x = df.apply( lambda x: pd.to_numeric(x,errors='ignore',downcast='float') )
if x.empty==True:
return False

Expand Down Expand Up @@ -779,13 +779,14 @@ def _doplot(self, data, ax, kind, subplots, errorbars, useindex, bw, yerr, kwarg
self.fig.colorbar(im,ax=ax)
axs = ax
elif kind == 'pie':
#if np.sum(data[data<0].sum(1)) < 0:
# self.showWarning('pie does not allow negative values')
# return
if useindex == False:
x=data.columns[0]
data.set_index(x,inplace=True)
if kwargs['legend'] == True:
lbls=None
else:
lbls = list(data.index)

axs = data.plot(ax=ax,kind='pie', labels=lbls, layout=layout,
autopct='%1.1f%%', subplots=True, **kwargs)
if lbls == None:
Expand Down

0 comments on commit eaf7283

Please sign in to comment.