Skip to content

Commit 289ea88

Browse files
authored
Use Sequence instead of List for drop (#46)
The advantage is that Sequence is covariant which allows passing in List[str], for example.
1 parent f3e5a49 commit 289ea88

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,39 +398,39 @@ class DataFrame(NDFrame, OpsMixin):
398398
fill_axis: AxisType = ...,
399399
broadcast_axis: Optional[AxisType] = ...,
400400
) -> DataFrame: ...
401-
def reindex(**kwargs) -> DataFrame: ...
401+
def reindex(self, **kwargs) -> DataFrame: ...
402402
@overload
403403
def drop(
404404
self,
405-
labels: Hashable | list[Hashable] = ...,
405+
labels: Hashable | Sequence[Hashable] = ...,
406406
*,
407407
axis: Axis = ...,
408-
index: Hashable | list[Hashable] = ...,
409-
columns: Hashable | list[Hashable] = ...,
408+
index: Hashable | Sequence[Hashable] = ...,
409+
columns: Hashable | Sequence[Hashable] = ...,
410410
level: Optional[Level] = ...,
411411
inplace: Literal[True],
412412
errors: IgnoreRaise = ...,
413413
) -> None: ...
414414
@overload
415415
def drop(
416416
self,
417-
labels: Hashable | list[Hashable] = ...,
417+
labels: Hashable | Sequence[Hashable] = ...,
418418
*,
419419
axis: Axis = ...,
420-
index: Hashable | list[Hashable] = ...,
421-
columns: Hashable | list[Hashable] = ...,
420+
index: Hashable | Sequence[Hashable] = ...,
421+
columns: Hashable | Sequence[Hashable] = ...,
422422
level: Optional[Level] = ...,
423423
inplace: Literal[False] = ...,
424424
errors: IgnoreRaise = ...,
425425
) -> DataFrame: ...
426426
@overload
427427
def drop(
428428
self,
429-
labels: Hashable | list[Hashable] = ...,
429+
labels: Hashable | Sequence[Hashable] = ...,
430430
*,
431431
axis: Axis = ...,
432-
index: Hashable | list[Hashable] = ...,
433-
columns: Hashable | list[Hashable] = ...,
432+
index: Hashable | Sequence[Hashable] = ...,
433+
columns: Hashable | Sequence[Hashable] = ...,
434434
level: Optional[Level] = ...,
435435
inplace: bool = ...,
436436
errors: IgnoreRaise = ...,

tests/test_frame.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ def test_types_drop() -> None:
200200
res6: pd.DataFrame = df.drop(index=1)
201201
res7: pd.DataFrame = df.drop(labels=0)
202202
res8: None = df.drop([0, 0], inplace=True)
203+
to_drop: List[str] = ["col1"]
204+
res9: pd.DataFrame = df.drop(columns=to_drop)
203205

204206

205207
def test_types_dropna() -> None:

0 commit comments

Comments
 (0)