Skip to content

2.2.x Enhance to_numeric to support hexadecimal, octal, and binary string inputs #59794

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
wants to merge 1 commit into from

Conversation

Staudinger0325
Copy link

Added a Helper Function parse_numeric:

Introduced a new internal function parse_numeric that attempts to parse strings with base prefixes:
Uses int(value, 0) to automatically detect the numerical base from the string prefix.
If parsing as an integer fails, it attempts to parse the value as a float.
Returns libmissing.NA if both parsing attempts fail.

Modified the Parsing Logic in to_numeric:

Replaced the call to lib.maybe_convert_numeric with a loop that applies parse_numeric to each element.
Handles errors according to the errors parameter:
Raises a ValueError with informative messaging when errors='raise'.
Sets unparseable values to NaN when errors='coerce'.
Utilizes a mask (new_mask) to track which values could not be parsed.

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.

1 participant