8000 df.rename(columns=...) does not accept dict variable · Issue #69 · VirtusLab/pandas-stubs · GitHub
[go: up one dir, main page]

Skip to content
df.rename(columns=...) does not accept dict variable #69
@janosh

Description

@janosh
import pandas as pd


df = pd.DataFrame(columns=["a"])

col_map = {"a": "b"}

df.rename(columns=col_map)

The above minimal example raises what appears to be a false type error on the last line due to passing columns=col_map:

Argument "columns" to "rename" of "DataFrame" has incompatible type "Dict[str, str]"; expected "Union[Mapping[Optional[Hashable], Any], Callable[[Optional[Hashable]], Optional[Hashable]], None]"mypy(error)

If instead I pass the dictionary as a literal value, the error disappears:

df.rename(columns={"a": "b"})  # all is well here

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0