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)
| 6055 | |
| 6056 | @derived_from(pd, ua_args=["downcast"]) |
| 6057 | def to_numeric(arg, errors="raise", downcast=None, meta=None): |
| 6058 | """ |
| 6059 | Return type depends on input. Delayed if scalar, otherwise same as input. |
| 6060 | For errors, only "raise" and "coerce" are allowed. |
| 6061 | """ |
| 6062 | if errors not in ("raise", "coerce"): |
| 6063 | raise ValueError("invalid error value specified") |
| 6064 | |
| 6065 | if pd_is_scalar(arg): |
| 6066 | if meta is not None: |
| 6067 | raise KeyError("``meta`` is not allowed when input is a scalar.") |
| 6068 | return delayed(pd.to_numeric, pure=True)(arg, errors=errors, downcast=downcast) |
| 6069 | |
| 6070 | if is_arraylike(arg): |
| 6071 | return new_collection( |
| 6072 | ToNumeric( |
| 6073 | from_array(arg).astype(arg.dtype), errors=errors, downcast=downcast |
| 6074 | ) |
| 6075 | ).to_dask_array(meta=meta) |
| 6076 | |
| 6077 | if is_series_like(arg): |
| 6078 | return new_collection( |
| 6079 | ToNumeric(frame=arg, errors=errors, downcast=downcast, meta=meta) |
| 6080 | ) |
| 6081 | |
| 6082 | raise TypeError( |
| 6083 | "arg must be a list, tuple, dask.array.Array, or dask.dataframe.Series" |
| 6084 | ) |
| 6085 | |
| 6086 | |
| 6087 | @wraps(pd.to_datetime) |