Skip to content

CLN: Remove default for columns in pivot #51367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8250,19 +8250,19 @@ def groupby(

Parameters
----------%s
columns : str or object or a list of str
Column to use to make new frame's columns.

.. versionchanged:: 1.1.0
Also accept list of columns names.

index : str or object or a list of str, optional
Column to use to make new frame's index. If None, uses
existing index.

.. versionchanged:: 1.1.0
Also accept list of index names.

columns : str or object or a list of str
Column to use to make new frame's columns.

.. versionchanged:: 1.1.0
Also accept list of columns names.

values : str, object or a list of the previous, optional
Column(s) to use for populating new frame's values. If not
specified, all remaining columns will be used and the result will
Expand Down Expand Up @@ -8385,9 +8385,7 @@ def groupby(

@Substitution("")
@Appender(_shared_docs["pivot"])
def pivot(
self, *, index=lib.NoDefault, columns=lib.NoDefault, values=lib.NoDefault
) -> DataFrame:
def pivot(self, *, columns, index=lib.NoDefault, values=lib.NoDefault) -> DataFrame:
from pandas.core.reshape.pivot import pivot

return pivot(self, index=index, columns=columns, values=values)
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,10 @@ def _convert_by(by):
def pivot(
data: DataFrame,
*,
columns: IndexLabel,
index: IndexLabel | lib.NoDefault = lib.NoDefault,
columns: IndexLabel | lib.NoDefault = lib.NoDefault,
values: IndexLabel | lib.NoDefault = lib.NoDefault,
) -> DataFrame:
if columns is lib.NoDefault:
raise TypeError("pivot() missing 1 required argument: 'columns'")

columns_listlike = com.convert_to_list_like(columns)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def test_pivot_with_list_like_values_nans(self, values, method):
def test_pivot_columns_none_raise_error(self):
# GH 30924
df = DataFrame({"col1": ["a", "b", "c"], "col2": [1, 2, 3], "col3": [1, 2, 3]})
msg = r"pivot\(\) missing 1 required argument: 'columns'"
msg = r"pivot\(\) missing 1 required keyword-only argument: 'columns'"
with pytest.raises(TypeError, match=msg):
df.pivot(index="col1", values="col3")

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

def test_pivot_columns_is_none(self):
Expand Down