Skip to content

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

Closed
wants to merge 10 commits into from
Closed

ENH : Allow to_sql to recognize single sql type #11886 #12053

wants to merge 10 commits into from

Conversation

RahulHP
Copy link
Contributor

@RahulHP RahulHP commented Jan 15, 2016

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.

@jreback
Copy link
Contributor

jreback commented Jan 15, 2016

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 }
Copy link
Contributor

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

Copy link
Contributor

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)

@jorisvandenbossche jorisvandenbossche added Enhancement IO SQL to_sql, read_sql, read_sql_query labels Jan 15, 2016
@jorisvandenbossche jorisvandenbossche added this to the 0.18.0 milestone Jan 15, 2016
@RahulHP
Copy link
Contributor Author

RahulHP commented Jan 16, 2016

Update: Writing the tests has been more difficult that I thought it would be. I am currently working on it though.

@jorisvandenbossche
Copy link
Member

@RahulHP For the test, best have a look at the existing test_dtype test (https://github.com/RahulHP/pandas/blob/to_sql-dictionary/pandas/io/tests/test_sql.py#L1502). You can see there how it is checked that the dtype is actually used in the database.
And maybe you can just add your test to that function.

@RahulHP
Copy link
Contributor Author

RahulHP commented Jan 17, 2016

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space before 'If'

@RahulHP
Copy link
Contributor Author

RahulHP commented Jan 18, 2016

Edits done

@jreback
Copy link
Contributor

jreback commented Feb 1, 2016

can you rebase / squash

@RahulHP
Copy link
Contributor Author

RahulHP commented Feb 3, 2016

Done, I followed the Contributing guide as best as I could but I think I may have messed it up.

@jorisvandenbossche
Copy link
Member

@RahulHP There indeed slipped in some changes from other PRs. Normally, by doing exactly this, it should be solved:

git checkout to_sql-dictionary
git fetch upstream
git rebase upstream/master
git push -f origin to_sql-dictionary

In the rebase step, you will possibly need to resolve some conflicts

@jreback jreback removed this from the 0.18.0 milestone Feb 9, 2016
@jreback
Copy link
Contributor

jreback commented Mar 23, 2016

can you rebase/update

@RahulHP
Copy link
Contributor Author

RahulHP commented Mar 26, 2016

Sorry, I'll work on this in a few days.

@jreback
Copy link
Contributor

jreback commented May 20, 2016

pls rebase / update

@RahulHP
Copy link
Contributor Author

RahulHP commented May 21, 2016

I have created a new pull request here #13252

@jorisvandenbossche jorisvandenbossche added this to the No action milestone Jun 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO SQL to_sql, read_sql, read_sql_query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants