Skip to content

Commit

Permalink
refactor(python): deprecate name argument in drop (#5099)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 5, 2022
1 parent dc9ce72 commit 6bede93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions py-polars/polars/internals/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4218,13 +4218,14 @@ def extend(self: DF, other: DF) -> DF:
self._df.extend(other._df)
return self

def drop(self: DF, name: str | list[str]) -> DF:
@deprecated_alias(name="columns")
def drop(self: DF, columns: str | list[str]) -> DF:
"""
Remove column from DataFrame and return as new.
Parameters
----------
name
columns
Column(s) to drop.
Examples
Expand All @@ -4251,14 +4252,14 @@ def drop(self: DF, name: str | list[str]) -> DF:
└─────┴─────┘
"""
if isinstance(name, list):
if isinstance(columns, list):
df = self.clone()

for n in name:
for n in columns:
df._df.drop_in_place(n)
return df

return self._from_pydf(self._df.drop(name))
return self._from_pydf(self._df.drop(columns))

def drop_in_place(self, name: str) -> pli.Series:
"""
Expand Down
5 changes: 4 additions & 1 deletion py-polars/tests/unit/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,10 @@ def test_extend() -> None:

def test_drop() -> None:
df = pl.DataFrame({"a": [2, 1, 3], "b": ["a", "b", "c"], "c": [1, 2, 3]})
df = df.drop("a")
df = df.drop(name="a") # type: ignore[call-arg]
assert df.shape == (3, 2)
df = pl.DataFrame({"a": [2, 1, 3], "b": ["a", "b", "c"], "c": [1, 2, 3]})
df = df.drop(columns="a")
assert df.shape == (3, 2)
df = pl.DataFrame({"a": [2, 1, 3], "b": ["a", "b", "c"], "c": [1, 2, 3]})
s = df.drop_in_place("a")
Expand Down

0 comments on commit 6bede93

Please sign in to comment.