Skip to content

df.rename(columns=...) does not accept dict variable #69

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
janosh opened this issue Aug 26, 2021 · 1 comment
Closed

df.rename(columns=...) does not accept dict variable #69

janosh opened this issue Aug 26, 2021 · 1 comment
Assignees

Comments

@janosh
Copy link

janosh commented Aug 26, 2021

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
@joannasendorek joannasendorek self-assigned this Aug 26, 2021
@joannasendorek
Copy link
Contributor

Hi @janosh, thank you for reporting this.

It is actually really interesting issue, because we use Renamer definition directly from pandas: https://github.com/pandas-dev/pandas/blob/v1.3.2/pandas/_typing.py#L136

I was able to re-create your problem and it seems that it partly because of: python/mypy#8293
I investigating some more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants