Skip to content

Commit a164326

Browse files
authored
TYP: Signature of "reindex" incompatible with supertype "NDFrame" (#40984)
1 parent 068b599 commit a164326

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

pandas/core/series.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -4601,8 +4601,17 @@ def set_axis(self, labels, axis: Axis = 0, inplace: bool = False):
46014601
optional_labels=_shared_doc_kwargs["optional_labels"],
46024602
optional_axis=_shared_doc_kwargs["optional_axis"],
46034603
)
4604-
def reindex(self, index=None, **kwargs):
4605-
return super().reindex(index=index, **kwargs)
4604+
def reindex(self, *args, **kwargs) -> Series:
4605+
if len(args) > 1:
4606+
raise TypeError("Only one positional argument ('index') is allowed")
4607+
if args:
4608+
(index,) = args
4609+
if "index" in kwargs:
4610+
raise TypeError(
4611+
"'index' passed as both positional and keyword argument"
4612+
)
4613+
kwargs.update({"index": index})
4614+
return super().reindex(**kwargs)
46064615

46074616
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
46084617
def drop(

pandas/tests/series/methods/test_reindex.py

+25
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,31 @@ def test_reindex_periodindex_with_object(p_values, o_values, values, expected_va
348348
tm.assert_series_equal(result, expected)
349349

350350

351+
def test_reindex_too_many_args():
352+
# GH 40980
353+
ser = Series([1, 2])
354+
with pytest.raises(
355+
TypeError, match=r"Only one positional argument \('index'\) is allowed"
356+
):
357+
ser.reindex([2, 3], False)
358+
359+
360+
def test_reindex_double_index():
361+
# GH 40980
362+
ser = Series([1, 2])
363+
msg = r"'index' passed as both positional and keyword argument"
364+
with pytest.raises(TypeError, match=msg):
365+
ser.reindex([2, 3], index=[3, 4])
366+
367+
368+
def test_reindex_no_posargs():
369+
# GH 40980
370+
ser = Series([1, 2])
371+
result = ser.reindex(index=[1, 0])
372+
expected = Series([2, 1], index=[1, 0])
373+
tm.assert_series_equal(result, expected)
374+
375+
351376
@pytest.mark.parametrize("values", [[["a"], ["x"]], [[], []]])
352377
def test_reindex_empty_with_level(values):
353378
# GH41170

0 commit comments

Comments
 (0)