Skip to content

pandas 3.0.1 raise numeric issue #123

@michaelabdelmalak

Description

@michaelabdelmalak

FutureWarning: errors='ignore' is deprecated and will raise in a future version. Use to_numeric without passing errors and catch exceptions explicitly instead
return data.apply(lambda x: pd.to_numeric(x, errors=errors))

In pandas 3.0.1, the to_numeric method has been modified such that it does not accept 'ignore' errors anymore

def to_numeric(
arg,
errors: DateTimeErrorChoices = "raise",
downcast: Literal["integer", "signed", "unsigned", "float"] | None = None,
dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default,
):
"""
Convert argument to a numeric type.

The default return dtype is `float64` or `int64`
depending on the data supplied. Use the `downcast` parameter
to obtain other dtypes.

Please note that precision loss may occur if really large numbers
are passed in. Due to the internal limitations of `ndarray`, if
numbers smaller than `-9223372036854775808` (np.iinfo(np.int64).min)
or larger than `18446744073709551615` (np.iinfo(np.uint64).max) are
passed in, it is very likely they will be converted to float so that
they can be stored in an `ndarray`. These warnings apply similarly to
`Series` since it internally leverages `ndarray`.

Parameters
----------
arg : scalar, list, tuple, 1-d array, or Series
    Argument to be converted.
errors : { 'raise', 'coerce'}, default 'raise'
    - If 'raise', then invalid parsing will raise an exception.
    - If 'coerce', then invalid parsing will be set as NaN.

This results in raising ValueError

return data.apply(lambda x: pd.to_numeric(x, errors=errors)) ~~~~~^^^^^^^^^^^^^^^^^^ File "...\Lib\site-packages\pandas\core\tools\numeric.py", line 183, in to_numeric raise ValueError("invalid error value specified")
ValueError: invalid error value specified

Solution:
we need to remove 'ignore' errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions