Skip to content

Commit f7a1b83

Browse files
authored
fix: #1008 columns in DataFrame.drop (#1131)
* fix: #1008 columns in DataFrame.drop * fix(comment): #1008 - #1131 (review)
1 parent 2323b10 commit f7a1b83

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pandas-stubs/core/generic.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class NDFrame(indexing.IndexingMixin):
289289
*,
290290
axis: Axis = ...,
291291
index: Hashable | Sequence[Hashable] | Index[Any] = ...,
292-
columns: Hashable | Sequence[Hashable] | Index[Any],
292+
columns: Hashable | Iterable[Hashable],
293293
level: Level | None = ...,
294294
inplace: Literal[True],
295295
errors: IgnoreRaise = ...,
@@ -301,7 +301,7 @@ class NDFrame(indexing.IndexingMixin):
301301
*,
302302
axis: Axis = ...,
303303
index: Hashable | Sequence[Hashable] | Index[Any],
304-
columns: Hashable | Sequence[Hashable] | Index[Any] = ...,
304+
columns: Hashable | Iterable[Hashable] = ...,
305305
level: Level | None = ...,
306306
inplace: Literal[True],
307307
errors: IgnoreRaise = ...,
@@ -325,7 +325,7 @@ class NDFrame(indexing.IndexingMixin):
325325
*,
326326
axis: Axis = ...,
327327
index: Hashable | Sequence[Hashable] | Index[Any] = ...,
328-
columns: Hashable | Sequence[Hashable] | Index[Any],
328+
columns: Hashable | Iterable[Hashable],
329329
level: Level | None = ...,
330330
inplace: Literal[False] = ...,
331331
errors: IgnoreRaise = ...,
@@ -337,7 +337,7 @@ class NDFrame(indexing.IndexingMixin):
337337
*,
338338
axis: Axis = ...,
339339
index: Hashable | Sequence[Hashable] | Index[Any],
340-
columns: Hashable | Sequence[Hashable] | Index[Any] = ...,
340+
columns: Hashable | Iterable[Hashable] = ...,
341341
level: Level | None = ...,
342342
inplace: Literal[False] = ...,
343343
errors: IgnoreRaise = ...,

tests/test_frame.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,11 @@ def test_types_drop() -> None:
344344
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
345345
check(assert_type(df.drop("col1", axis=1), pd.DataFrame), pd.DataFrame)
346346
check(assert_type(df.drop(columns=["col1"]), pd.DataFrame), pd.DataFrame)
347+
check(assert_type(df.drop(columns=pd.Index(["col1"])), pd.DataFrame), pd.DataFrame)
348+
check(assert_type(df.drop(columns={"col1"}), pd.DataFrame), pd.DataFrame)
349+
check(assert_type(df.drop(columns=iter(["col1"])), pd.DataFrame), pd.DataFrame)
347350
check(assert_type(df.drop([0]), pd.DataFrame), pd.DataFrame)
348351
check(assert_type(df.drop(index=[0]), pd.DataFrame), pd.DataFrame)
349-
check(assert_type(df.drop(columns=["col1"]), pd.DataFrame), pd.DataFrame)
350352
check(assert_type(df.drop(index=1), pd.DataFrame), pd.DataFrame)
351353
check(assert_type(df.drop(labels=0), pd.DataFrame), pd.DataFrame)
352354
assert assert_type(df.drop([0, 0], inplace=True), None) is None

0 commit comments

Comments
 (0)