@@ -88,21 +88,53 @@ def _compare(self, result, expected):
88
88
def test_rename (self ):
89
89
90
90
# single axis
91
+ idx = list ('ABCD' )
92
+ # relabeling values passed into self.rename
93
+ args = [
94
+ str .lower ,
95
+ {x : x .lower () for x in idx },
96
+ Series ({x : x .lower () for x in idx }),
97
+ ]
98
+
91
99
for axis in self ._axes ():
92
- kwargs = {axis : list ( 'ABCD' ) }
100
+ kwargs = {axis : idx }
93
101
obj = self ._construct (4 , ** kwargs )
94
102
95
- # no values passed
96
- # self.assertRaises(Exception, o.rename(str.lower))
97
-
98
- # rename a single axis
99
- result = obj .rename (** {axis : str .lower })
100
- expected = obj .copy ()
101
- setattr (expected , axis , list ('abcd' ))
102
- self ._compare (result , expected )
103
+ for arg in args :
104
+ # rename a single axis
105
+ result = obj .rename (** {axis : arg })
106
+ expected = obj .copy ()
107
+ setattr (expected , axis , list ('abcd' ))
108
+ self ._compare (result , expected )
103
109
104
110
# multiple axes at once
105
111
112
+ def test_rename_axis (self ):
113
+ idx = list ('ABCD' )
114
+ # relabeling values passed into self.rename
115
+ args = [
116
+ str .lower ,
117
+ {x : x .lower () for x in idx },
118
+ Series ({x : x .lower () for x in idx }),
119
+ ]
120
+
121
+ for axis in self ._axes ():
122
+ kwargs = {axis : idx }
123
+ obj = self ._construct (4 , ** kwargs )
124
+
125
+ for arg in args :
126
+ # rename a single axis
127
+ result = obj .rename_axis (arg , axis = axis )
128
+ expected = obj .copy ()
129
+ setattr (expected , axis , list ('abcd' ))
130
+ self ._compare (result , expected )
131
+ # scalar values
132
+ for arg in ['foo' , None ]:
133
+ result = obj .rename_axis (arg , axis = axis )
134
+ expected = obj .copy ()
135
+ getattr (expected , axis ).name = arg
136
+ self ._compare (result , expected )
137
+
106
138
def test_get_numeric_data (self ):
107
139
108
140
n = 4
0 commit comments