Skip to content

Commit 107c64f

Browse files
authored
CLN: Remove default for columns in pivot (#51367)
* CLN: Remove default for columns in pivot * CLN: Remove default for columns in pivot
1 parent d1095bc commit 107c64f

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

pandas/core/frame.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8252,19 +8252,19 @@ def groupby(
82528252
82538253
Parameters
82548254
----------%s
8255+
columns : str or object or a list of str
8256+
Column to use to make new frame's columns.
8257+
8258+
.. versionchanged:: 1.1.0
8259+
Also accept list of columns names.
8260+
82558261
index : str or object or a list of str, optional
82568262
Column to use to make new frame's index. If None, uses
82578263
existing index.
82588264
82598265
.. versionchanged:: 1.1.0
82608266
Also accept list of index names.
82618267
8262-
columns : str or object or a list of str
8263-
Column to use to make new frame's columns.
8264-
8265-
.. versionchanged:: 1.1.0
8266-
Also accept list of columns names.
8267-
82688268
values : str, object or a list of the previous, optional
82698269
Column(s) to use for populating new frame's values. If not
82708270
specified, all remaining columns will be used and the result will
@@ -8387,9 +8387,7 @@ def groupby(
83878387

83888388
@Substitution("")
83898389
@Appender(_shared_docs["pivot"])
8390-
def pivot(
8391-
self, *, index=lib.NoDefault, columns=lib.NoDefault, values=lib.NoDefault
8392-
) -> DataFrame:
8390+
def pivot(self, *, columns, index=lib.NoDefault, values=lib.NoDefault) -> DataFrame:
83938391
from pandas.core.reshape.pivot import pivot
83948392

83958393
return pivot(self, index=index, columns=columns, values=values)

pandas/core/reshape/pivot.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,10 @@ def _convert_by(by):
500500
def pivot(
501501
data: DataFrame,
502502
*,
503+
columns: IndexLabel,
503504
index: IndexLabel | lib.NoDefault = lib.NoDefault,
504-
columns: IndexLabel | lib.NoDefault = lib.NoDefault,
505505
values: IndexLabel | lib.NoDefault = lib.NoDefault,
506506
) -> DataFrame:
507-
if columns is lib.NoDefault:
508-
raise TypeError("pivot() missing 1 required argument: 'columns'")
509507

510508
columns_listlike = com.convert_to_list_like(columns)
511509

pandas/tests/reshape/test_pivot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ def test_pivot_with_list_like_values_nans(self, values, method):
799799
def test_pivot_columns_none_raise_error(self):
800800
# GH 30924
801801
df = DataFrame({"col1": ["a", "b", "c"], "col2": [1, 2, 3], "col3": [1, 2, 3]})
802-
msg = r"pivot\(\) missing 1 required argument: 'columns'"
802+
msg = r"pivot\(\) missing 1 required keyword-only argument: 'columns'"
803803
with pytest.raises(TypeError, match=msg):
804804
df.pivot(index="col1", values="col3")
805805

@@ -2513,7 +2513,7 @@ def test_pivot_index_list_values_none_immutable_args(self):
25132513
def test_pivot_columns_not_given(self):
25142514
# GH#48293
25152515
df = DataFrame({"a": [1], "b": 1})
2516-
with pytest.raises(TypeError, match="missing 1 required argument"):
2516+
with pytest.raises(TypeError, match="missing 1 required keyword-only argument"):
25172517
df.pivot()
25182518

25192519
def test_pivot_columns_is_none(self):

0 commit comments

Comments
 (0)