Skip to content

Unexpected keyword argument #48914

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

Closed
Closed
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
7 changes: 6 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,12 @@ def _with_infer(cls, *args, **kwargs):
return result

@cache_readonly
def _constructor(self: _IndexT) -> type[_IndexT]:
def _constructor(
self: _IndexT,
name: Hashable | None = None,
copy: bool | None = None,
dtype=None,
Comment on lines +743 to +745
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR

I don't think this is the right fix, as these arguments (name, copy, ...) get passed to NumericIndex, rather than to _constructor

Copy link
Contributor Author

@shalearkane shalearkane Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I looked into the code. Classes ExtensionIndex, MultiIndex and NumericIndex inherits from the base class Index.

And

  • MultiIndex and
  • RangeIndex (which inherits from NumericIndex)

is overriding the _constructor method.

So should I include the function arguments in the _constructor method of those classes too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, this isn't resolved - I think the issue is that pylint can't tell that @cache_readonly makes _constructor act like a property and that it doesn't take arguments

I'll have another look later

) -> type[_IndexT]:
return type(self)

@final
Expand Down
7 changes: 6 additions & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,12 @@ def _engine(self):
# Return type "Callable[..., MultiIndex]" of "_constructor" incompatible with return
# type "Type[MultiIndex]" in supertype "Index"
@property
def _constructor(self) -> Callable[..., MultiIndex]: # type: ignore[override]
def _constructor(
self: MultiIndex,
name: Hashable | None = None,
copy: bool | None = None,
dtype=None,
) -> Callable[..., MultiIndex]: # type: ignore[override]
return type(self).from_tuples

@doc(Index._shallow_copy)
Expand Down
7 changes: 6 additions & 1 deletion pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ def _simple_new(cls, values: range, name: Hashable = None) -> RangeIndex:
# error: Return type "Type[Int64Index]" of "_constructor" incompatible with return
# type "Type[RangeIndex]" in supertype "Index"
@cache_readonly
def _constructor(self) -> type[Int64Index]: # type: ignore[override]
def _constructor(
self: RangeIndex,
name: Hashable | None = None,
copy: bool | None = None,
dtype=None
) -> type[Int64Index]: # type: ignore[override]
"""return the class to use for construction"""
return Int64Index

Expand Down