-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
cannot safely convert passed user dtype of <f8 for object dtyped data in column *** #13237
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
Comments
Well the error message speaks for itself. Your values are above the float limit. Why would you actually want to do this?
|
I hope it can read it right and get the value ,it works well in 32bit ,but no ok under 64bit |
This gives the same error on 32-bit windows as well. You are trying to fool with floats right at the limit, a recipe for disaster. No reason at all to do this. |
hope it can transform correctly , as the max_dbl is still a legal float ,not a wrong float just the board of the float number |
Isn't it bad that |
@p-himik well there are a couple of considerations
None of these are really good options. So sure, in an ideal world things are unified. I would say that |
Oh, at least But can a similar thing be added to |
can you show a copy-pastable example of what you mean? |
Here's what In [137]: pd.to_numeric(o)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
pandas/src/inference.pyx in pandas.lib.maybe_convert_numeric (pandas/lib.c:55708)()
ValueError: Unable to parse string "52721156299871854681072370812488856336599863860274272781560003496046130816295143841376557767523688876482371118681808060318819187029855011862637267061548684520491431327693943042785705302632892888308342787190965977140539558800921069356177102235514666302335984730634641934384020650987601849970936578094137344.00000" And here's what In [138]: d = pd.read_csv('EUR.UC.gwas.assoc', delim_whitespace=True, usecols=['OR'], dtype={'OR': np.float64})
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
pandas/parser.pyx in pandas.parser.TextReader._convert_tokens (pandas/parser.c:14411)()
TypeError: Cannot cast array from dtype('O') to dtype('float64') according to the rule 'safe'
During handling of the above exception, another exception occurred:
[... long stacktrace ...]
pandas/parser.pyx in pandas.parser.TextReader._convert_tokens (pandas/parser.c:14632)()
ValueError: cannot safely convert passed user dtype of float64 for object dtyped data in column 8 The problem here is that it's impossible to tell anything about what's wrong with the data without loading and checking it manually. Apart from being a mild inconvenience, in some cases with strict data regulations manual checking can be just unfeasible. |
@p-himik ahh I c. Well it would be quite simple to make a better error message (e.g. adding the problematic value, line number etc.). Want to do a PR? (or if not, please open an issue with this example). |
I'll try to do a PR in a week or so. I've never been to the C part of Pandas before. :) |
actually this is cython so should be pretty straightforward :> |
Just pass float_precision='high' to pd.read_csv |
Code Sample, a copy-pastable example if possible
under 64bit windows problem
it's ok on win32 platform ,but it does not work under 64bit,unless I remove the dtype and read the DataFrame and then transform the format asfloat ...
I cant debug into the file
market_head_list = ['TradingDay','ClosePrice']
dt['TradingDay'] = np.str
dt['ClosePrice'] = float # I used np.float64 too ,but it still cant work
csv_str_now ='1.7976931348623157e+308, 1.7976931348623157e+308 '
output of
pd.show_versions()
pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 20.3
Cython: 0.23.4
numpy: 1.11.0
scipy: 0.17.0
statsmodels: None
xarray: None
IPython: 4.1.2
sphinx: 1.3.5
patsy: 0.4.0
dateutil: 2.5.1
pytz: 2016.2
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.5.2
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.8.4
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.39.0
pandas_datareader: None
File "pandas\parser.pyx", line 805, in pandas.parser.TextReader.read (pandas\parser.c:8620)
File "pandas\parser.pyx", line 827, in pandas.parser.TextReader._read_low_memory (pandas\parser.c:8876)
File "pandas\parser.pyx", line 904, in pandas.parser.TextReader._read_rows (pandas\parser.c:9893)
File "pandas\parser.pyx", line 1011, in pandas.parser.TextReader._convert_column_data (pandas\parser.c:11286)
File "pandas\parser.pyx", line 1092, in pandas.parser.TextReader._convert_tokens (pandas\parser.c:12659)
ValueError: cannot safely convert passed user dtype of <f8 for object dtyped data in column 1
The text was updated successfully, but these errors were encountered: