Return type depends on input. Delayed if scalar, otherwise same as input. For errors, only "raise" and "coerce" are allowed.
(arg, errors="raise", downcast=None, meta=None)
| 6126 | |
| 6127 | @derived_from(pd, ua_args=["downcast"]) |
| 6128 | def to_numeric(arg, errors="raise", downcast=None, meta=None): |
| 6129 | """ |
| 6130 | Return type depends on input. Delayed if scalar, otherwise same as input. |
| 6131 | For errors, only "raise" and "coerce" are allowed. |
| 6132 | """ |
| 6133 | if errors not in ("raise", "coerce"): |
| 6134 | raise ValueError("invalid error value specified") |
| 6135 | |
| 6136 | if pd_is_scalar(arg): |
| 6137 | if meta is not None: |
| 6138 | raise KeyError("``meta`` is not allowed when input is a scalar.") |
| 6139 | return delayed(pd.to_numeric, pure=True)(arg, errors=errors, downcast=downcast) |
| 6140 | |
| 6141 | if is_arraylike(arg): |
| 6142 | return new_collection( |
| 6143 | ToNumeric( |
| 6144 | from_array(arg).astype(arg.dtype), errors=errors, downcast=downcast |
| 6145 | ) |
| 6146 | ).to_dask_array(meta=meta) |
| 6147 | |
| 6148 | if is_series_like(arg): |
| 6149 | return new_collection( |
| 6150 | ToNumeric(frame=arg, errors=errors, downcast=downcast, meta=meta) |
| 6151 | ) |
| 6152 | |
| 6153 | raise TypeError( |
| 6154 | "arg must be a list, tuple, dask.array.Array, or dask.dataframe.Series" |
| 6155 | ) |
| 6156 | |
| 6157 | |
| 6158 | @wraps(pd.to_datetime) |