-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH : Allow to_sql to recognize single sql type #11886 #12053
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
tests! |
@@ -564,6 +564,10 @@ def to_sql(frame, name, con, flavor='sqlite', schema=None, if_exists='fail', | |||
raise NotImplementedError("'frame' argument should be either a " | |||
"Series or a DataFrame") | |||
|
|||
if dtype and not isinstance(dtype,dict): | |||
temp_type = dtype | |||
dtype = { col_name : temp_type for col_name in frame } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think flake8 will complain about this line. Need to get rid of the spaces around the curly braces.
Oh, also space after the common above in the isinstance
check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also is_dictlike
(which isn't a perfect function but at least improvements will be encapsulated)
Update: Writing the tests has been more difficult that I thought it would be. I am currently working on it though. |
@RahulHP For the test, best have a look at the existing |
Update: I added the new test and it passes the Travis build. |
Optional specifying the datatype for columns. The SQL type should | ||
be a SQLAlchemy type. | ||
be a SQLAlchemy type.If all columns are of the same type, one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space before 'If'
Edits done |
can you rebase / squash |
Done, I followed the Contributing guide as best as I could but I think I may have messed it up. |
@RahulHP There indeed slipped in some changes from other PRs. Normally, by doing exactly this, it should be solved:
In the rebase step, you will possibly need to resolve some conflicts |
can you rebase/update |
Sorry, I'll work on this in a few days. |
pls rebase / update |
I have created a new pull request here #13252 |
Continued in #13252
This solves #11886
It checks whether the passed dtype variable is a dictionary.
If not, it creates a new dictionary with keys as the columns of the dataframe.
It then passes this dictionary to the pandasSQL_builder.