@@ -5976,13 +5976,18 @@ def rename(self, columns, errors='ignore', inplace=True, **kwargs):
5976
5976
-------
5977
5977
:class:`CASTable`
5978
5978
'''
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 )
5979
5984
5980
5985
#Columns is a dict:
5981
5986
alterTable = []
5982
5987
if isinstance (columns , dict ):
5983
5988
#Convert Pandas-style dict to CAS-style list of dicts
5984
5989
for oldName , newName in columns .items ():
5985
- if oldName in self .columns :
5990
+ if oldName in table .columns :
5986
5991
alterTable .append ({'name' : oldName , 'rename' : newName })
5987
5992
#If we encounter a key that doesn't exist as column
5988
5993
#and we are raising errors, we do that here
@@ -5992,14 +5997,14 @@ def rename(self, columns, errors='ignore', inplace=True, **kwargs):
5992
5997
#Columns is a function:
5993
5998
elif callable (columns ):
5994
5999
#Iterate through all table columns and apply function
5995
- for col in self .columns :
6000
+ for col in table .columns :
5996
6001
alterTable .append ({'name' : col , 'rename' : columns (col )})
5997
6002
else :
5998
6003
raise TypeError ("Columns must be a dict or function" )
5999
6004
6000
6005
#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
6003
6008
6004
6009
def reset_index (self , level = None , drop = False , inplace = False ,
6005
6010
col_level = 0 , col_fill = '' , ** kwargs ):
0 commit comments