Skip to content

ENH: Better error message for trying to convert to "double," type #60685

Closed
@benrutter

Description

@benrutter

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I (don't ask how 😅) came over the fact that this:

pd.DataFrame({"a": [1, 2, 3]}).astype("hurdy-gurdy")

Raises a helpful 'TypeError: data type "hurdy-gurdy" not understood message'

But this doesn't happen if the incorrect type is "double," (I'm not sure why but I assume something around the fact that pandas needs to check for types such as "double[pyarrow]").

This code:

pd.DataFrame({"a": [1, 2, 3]}).astype("double,")

Raises the error: "TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''".

Feature Description

Throw the safe "double," is not a valid type error message

Alternative Solutions

Probably involves digging slightly into the part of the code that's throwing an error - I'd love to put in a PR if this is something that'd be accepted?

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions