Skip to content

Commit b32c238

Browse files
author
Michael Erickson
committed
Added implace functionality
1 parent 7279258 commit b32c238

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

swat/cas/table.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5976,13 +5976,18 @@ def rename(self, columns, errors='ignore', inplace=True, **kwargs):
59765976
-------
59775977
:class:`CASTable`
59785978
'''
5979+
#If we are working in place, our working table is the table itself
5980+
table = self
5981+
#If not, we need to make a copy
5982+
if not inplace:
5983+
table = copy.deepcopy(self)
59795984

59805985
#Columns is a dict:
59815986
alterTable = []
59825987
if isinstance(columns, dict):
59835988
#Convert Pandas-style dict to CAS-style list of dicts
59845989
for oldName, newName in columns.items():
5985-
if oldName in self.columns:
5990+
if oldName in table.columns:
59865991
alterTable.append({'name': oldName, 'rename': newName})
59875992
#If we encounter a key that doesn't exist as column
59885993
#and we are raising errors, we do that here
@@ -5992,14 +5997,14 @@ def rename(self, columns, errors='ignore', inplace=True, **kwargs):
59925997
#Columns is a function:
59935998
elif callable(columns):
59945999
#Iterate through all table columns and apply function
5995-
for col in self.columns:
6000+
for col in table.columns:
59966001
alterTable.append({'name': col, 'rename': columns(col)})
59976002
else:
59986003
raise TypeError("Columns must be a dict or function")
59996004

60006005
#Use list of dicts to rename using alterTable action
6001-
self._retrieve('alterTable', columns=alterTable)
6002-
return self
6006+
table._retrieve('alterTable', columns=alterTable)
6007+
return table
60036008

60046009
def reset_index(self, level=None, drop=False, inplace=False,
60056010
col_level=0, col_fill='', **kwargs):

0 commit comments

Comments
 (0)