Skip to content

Commit b66e9e2

Browse files
committed
whatsnew
1 parent 177a440 commit b66e9e2

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

doc/source/whatsnew/v1.0.0.rst

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,68 @@ Backwards incompatible API changes
174174
175175
pd.arrays.IntervalArray.from_tuples([(0, 1), (2, 3)])
176176
177+
``DataFrame.rename`` now only accepts one positional argument
178+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
179+
180+
- :meth:`DataFrame.rename` would previously accept positional arguments that would lead
181+
to ambiguous or undefined behavior. From pandas 1.0, only the very first argument, which
182+
maps labels to their new names along the default axis, is allowed to be passed by position
183+
(:issue:`29136`).
184+
185+
*pandas 0.25.x*
186+
187+
.. code-block:: ipython
188+
189+
In [1]: df = pd.DataFrame([[1]])
190+
In [2]: df.rename({0: 1}, {0: 2})
191+
FutureWarning: ...Use named arguments to resolve ambiguity...
192+
Out[2]:
193+
2
194+
1 1
195+
196+
*pandas 1.0.0*
197+
.. ipython:: python
198+
199+
df.rename({0: 1}, {0: 2})
200+
201+
Note that errors will now be raised when conflicting or potentially ambiguous arguments are provided.
202+
203+
*pandas 0.25.x*
204+
205+
.. code-block:: ipython
206+
207+
In [1]: df.rename({0: 1}, index={0: 2})
208+
Out[1]:
209+
0
210+
1 1
211+
212+
In [2]: df.rename(mapper={0: 1}, index={0: 2})
213+
Out[2]:
214+
0
215+
2 1
216+
217+
*pandas 1.0.0*
218+
219+
.. ipython:: python
220+
221+
df.rename({0: 1}, index={0: 2})
222+
df.rename(mapper={0: 1}, index={0: 2})
223+
224+
You can still change the axis along which the first positional argument is applied by
225+
supplying the ``axis`` keyword argument.
226+
227+
.. ipython:: python
228+
229+
df.rename({0: 1})
230+
df.rename({0: 1}, axis=1)
231+
232+
If you would like to update both the index and column labels, be sure to use the respective
233+
keywords.
234+
235+
.. ipython:: python
236+
237+
df.rename(index={0: 1}, columns={0: 2})
238+
177239
178240
.. _whatsnew_1000.api.other:
179241

0 commit comments

Comments
 (0)