-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: convert nan to None before insert data into mysql #4200
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
Conversation
@simomo Can you include a test demonstrating expected behavior? See pandas/io/tests/test_sql.py for examples. Also, of course including
|
This is quite complicated and shouldn't be done this way. The main issue is different reprs for datetime/non-datetime. There are better ways of doing this (these are internal routines), e.g. see You are going to need to segregate by block type, then convert or (not-convert) as needed, substituting appropriate 'null' sentinals (which might be different for different flavors?) |
@jreback Why is it necessary to have different sentinals for NaN and NaT? (I agree this should be done on write/like _save_chunk...) |
Its not necessary per se, but I suspect that the different SQL have different sentials (if for perf though...this may need to be optimized |
Idea being to abstract problem of None to SQLAlchemy, assuming it Just WorksTM. Which I thought was kind of the point of it... Yeah, perf could be an issue - in which case we'll end up writing a load of platform specific stuff? :s |
I am not sure what perf diff will be, just have to profile it. You might simply want to something like:
prob should work and be pretty fast (not 100% sure what this will do to dates though) |
I think you are going to have to do specific backend specific conversions (mostly on NaN/None, but also datetimes). IIRC mysql stores dates as strings? though some of this may be converted from datestimes |
@danielballan do we care how it's stored... provided the roundtrip works (and probably also that the dtype is sensible) is all good...? Do we need to know in order to query (for None)? Can't SQLAlchemy compile your query in a clever way (worrying about the platform specific bit), maybe I've got it totally wrong? |
No, I don't think we care. The second comment on the SO question is troubling, or at least confusing to me. I think all flavors of SQL just have NULL, and we'll want those to ultimately come out as np.nan. Certainty not 'NaN'. |
@danielballan you will for sure need to do type conversions on the readback, e.g. make sure dates are correct (you can just use you also may want to do |
related to #4163 |
Filling NaN with None:
produces an error:
Is it the same bug as reported in this thread? |
@stared what are you trying to do? |
@jreback Convert At the same time I can do (i.e. there is no error):
which seems to be equivalent to:
|
well aside fro the apply be MUCH slower, fillna also does dtype infererence. I meant what is your purpose in doing this? |
@jreback I am performing an outer join of two tables, so I am getting BTW: Why |
ahh...then this is the same issue (has to do with exporting well,
|
@stared |
@hayd I believe you are going to do this as part of big SQL refactor (and its already linked), so closing |
For issue #4199