Skip to content

DOC: Clarify to_numeric behavior for numeric dtypes #61903

@chilin0525

Description

@chilin0525

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/dev/reference/api/pandas.to_numeric.html#pandas-to-numeric

Documentation problem

The docstring for the to_numeric function needs to be improved for clarity and accuracy. The current documentation states, "The default return dtype is float64 or int64," which can be misleading. This statement doesn't account for cases where the input data is already of a numeric ExtensionDtype (e.g., Int32, Float32, or Arrow dtypes where _is_numeric is True). In these instances, to_numeric correctly preserves the original dtype rather than converting it, making the current documentation incomplete.

Suggested fix for documentation

  1. If the input is already of a numeric dtype, its dtype is preserved.
  2. The conversion to a default float64 or int64 dtype primarily applies to non-numeric inputs.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions