Skip to content

allow a dict in DataFrame.astype() #449

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

Merged
merged 4 commits into from
Nov 29, 2022
Merged

Conversation

Dr-Irv
Copy link
Collaborator

@Dr-Irv Dr-Irv commented Nov 26, 2022

@Dr-Irv Dr-Irv requested a review from bashtage November 26, 2022 00:40
@@ -1357,7 +1357,7 @@ class DataFrame(NDFrame, OpsMixin):
) -> DataFrame: ...
def astype(
self,
dtype: _str | Dtype | dict[_str, _str | Dtype] | Series,
dtype: _str | Dtype | Mapping[_str, _str | Dtype] | Series,
Copy link
Member

Choose a reason for hiding this comment

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

the keys can probably be any Hashable(T) as the columns might not be str.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done in 5ff40de

Copy link
Member

Choose a reason for hiding this comment

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

Could maybe add a test for a non-str column

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I modified the test to do a mix of column "names", i.e., a string and an int in fa76285

@twoertwein twoertwein merged commit c74909e into pandas-dev:main Nov 29, 2022
@twoertwein
Copy link
Member

Thank you @Dr-Irv !

@Dr-Irv Dr-Irv deleted the astype_dict branch December 28, 2022 15:20
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

Successfully merging this pull request may close these issues.

error: Argument 1 to "astype" of "DataFrame" has incompatible type "Dict[str, str]" [arg-type]
2 participants