#NEWLINE# def to_numeric( arg , errors = 'raise' ) : #NEWLINE# #INDENT# "\n    Convert argument to a numeric type.\n\n    Parameters\n    ----------\n    arg : list, tuple, 1-d array, or Series\n    errors : {'ignore', 'raise', 'coerce'}, default 'raise'\n        - If 'raise', then invalid parsing will raise an exception\n        - If 'coerce', then invalid parsing will be set as NaN\n        - If 'ignore', then invalid parsing will return the input\n\n    Returns\n    -------\n    ret : numeric if parsing succeeded.\n        Return type depends on input.  Series if Series, otherwise ndarray\n\n    Examples\n    --------\n    Take separate series and convert to numeric, coercing when told to\n\n    >>> import pandas as pd\n    >>> s = pd.Series(['1.0', '2', -3])\n    >>> pd.to_numeric(s)\n    >>> s = pd.Series(['apple', '1.0', '2', -3])\n    >>> pd.to_numeric(s, errors='ignore')\n    >>> pd.to_numeric(s, errors='coerce')\n    " #NEWLINE# index = name = None #NEWLINE# if isinstance ( arg , pd . Series ) : #NEWLINE# #INDENT# ( index , name ) = ( arg . index , arg . name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( arg , ( list , tuple ) ) : #NEWLINE# #INDENT# arg = np . array ( arg , dtype = 'O' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( getattr ( arg , 'ndim' , 1 ) > 1 ) : #NEWLINE# #INDENT# raise TypeError ( 'arg must be a list, tuple, 1-d array, or Series' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# conv = arg #NEWLINE# arg = com . _ensure_object ( arg ) #NEWLINE# coerce_numeric = ( False if ( errors in ( 'ignore' , 'raise' ) ) else True ) #NEWLINE# try : #NEWLINE# #INDENT# conv = lib . maybe_convert_numeric ( arg , set ( ) , coerce_numeric = coerce_numeric ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# if ( name == 'raise' ) : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# if ( index is not None ) : #NEWLINE# #INDENT# return pd . Series ( conv , index = index , name = name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return conv