Skip to content
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

API: add astype coerce argument / remove raise_on_error #8332

Closed
jreback opened this issue Sep 20, 2014 · 2 comments
Closed

API: add astype coerce argument / remove raise_on_error #8332

jreback opened this issue Sep 20, 2014 · 2 comments
Labels
API Design Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Comments

@jreback
Copy link
Contributor

jreback commented Sep 20, 2014

http://stackoverflow.com/questions/25952790/convert-pandas-series-from-dtype-object-to-float-and-errors-to-nans/25952844#25952844

maybe removeraise_on_error and rename to coerce (more inline with the rest of pandas API)

In [30]: pd.Series([1,2,3,4,'.']).convert_objects(convert_numeric=True)
Out[30]: 
0     1
1     2
2     3
3     4
4   NaN
dtype: float64

I suspect this might make a nice API as well

s = pd.Series([1,2,3,4,'.'])
s.astype('float64', coerce=True)

maybe coerce=True|None|'raise' make sense

@jreback jreback added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Dtype Conversions Unexpected or buggy dtype conversions API Design labels Sep 20, 2014
@jreback jreback added this to the 0.15.1 milestone Sep 20, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@TomAugspurger
Copy link
Contributor

We don't want to overload .astype any further.

We have pd.to_numeric(s, errors='coerce'), and DataFrame.apply(pd.to_numeric, errors='coerce')

@TomAugspurger TomAugspurger modified the milestones: Contributions Welcome, No action Jul 6, 2018
@tdpetrou
Copy link
Contributor

I'd really like to see astype add the option for 'coerce'. Its quite confusing to have to be aware of the to_numeric function. Using it with apply is very ugly. It's just a single more option and a very good one in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Dtype Conversions Unexpected or buggy dtype conversions Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

No branches or pull requests

3 participants