Skip to content

FIX: to_sql takes the boolean column as text column #7678

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

Merged
merged 1 commit into from
Jul 7, 2014
Merged

FIX: to_sql takes the boolean column as text column #7678

merged 1 commit into from
Jul 7, 2014

Conversation

yelite
Copy link
Contributor

@yelite yelite commented Jul 7, 2014

In the original code, com.is_bool(arr_or_dtype) checks whether arr_or_dtype is a boolean value instead of a boolean dtype.

A new function is_bool_dtype is added to pandas.core.common to fix this bug.

@yelite yelite changed the title Fix a bug that to_sql takes the boolean column as text column FIX a bug that to_sql takes the boolean column as text column Jul 7, 2014
@yelite yelite changed the title FIX a bug that to_sql takes the boolean column as text column FIX: to_sql takes the boolean column as text column Jul 7, 2014
@jorisvandenbossche
Copy link
Member

@yelite Thanks for the contribution!

Can you add a test for it (look in io/tests/test_sql.py)? You can for example take the example you were working with where you experienced the issue, and slim this down to a small test case. Just ask if something is not clear for this.

@jreback There isn't already a function like this somewhere?

@jreback
Copy link
Contributor

jreback commented Jul 7, 2014

this is already in master (recently added)
core/common iirc

@jorisvandenbossche
Copy link
Member

@yelite
Copy link
Contributor Author

yelite commented Jul 7, 2014

@jorisvandenbossche
Great, I removed my function from the commit and added a simple test.

@jorisvandenbossche
Copy link
Member

@yelite I wanted to say your test would fail because of the index, but you already adapated it!

Can you add a line in doc/source/v0.14.1.txt in the bug fixes section for this?

self.conn, flavor='sqlite', index=False)
result = sql.read_sql_table('test_frame5', self.conn)

self.assertTrue((self.test_frame2.dtypes==result.dtypes).all(),
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be tm.assert_frame_equal(self.test_frame2,result)

@yelite
Copy link
Contributor Author

yelite commented Jul 7, 2014

@jreback

AssertionError: attr is not equal [inferred_type]: 'string' != 'unicode'

https://travis-ci.org/pydata/pandas/jobs/29317980

Does this difference between string and unicode really matter? Should we omit it?

@jreback
Copy link
Contributor

jreback commented Jul 7, 2014

so the returned data is unicode. so 2 solns:

  • on the test calls tests with (and w/out) the server returning unicode (IIRC they usually and by default do, but can be turned on/off

e.g. in sqlalchemy (sort of manuall), I usually do

engine.dialect.description_encoding=None (with postgresql),

  • add an option to assert_frame_equal to ignore this different (better soln I think)

@jorisvandenbossche ?

@yelite
Copy link
Contributor Author

yelite commented Jul 7, 2014

@jreback
A mistake. I thought check_column_type means checking the type of each column. Actually it checks the type of column block. So it's not important in this test. I set it to False now.

@jorisvandenbossche
I added a line at the end of doc/source/v0.14.1.txt. Is that ok or it should be organized by section?

@jorisvandenbossche
Copy link
Member

For the whatsnew note, that is OK.

And the column names of the original dataframe and the result from read_sql are indeed different in type ... (but indeed, not important to test that here).

@jreback jreback added this to the 0.14.1 milestone Jul 7, 2014
@jorisvandenbossche
Copy link
Member

Travis is green, so merging.
Thanks a lot! (and if you want to tackle other issues, don't hesitate :-))

jorisvandenbossche added a commit that referenced this pull request Jul 7, 2014
FIX: to_sql takes the boolean column as text column
@jorisvandenbossche jorisvandenbossche merged commit 71b7087 into pandas-dev:master Jul 7, 2014
@jreback
Copy link
Contributor

jreback commented Jul 7, 2014

https://travis-ci.org/pydata/pandas/jobs/29341707

I have seen this happen if something weird is passed to an is_***_dtype (np.dtype craps out).

let's see if it repeats

@jorisvandenbossche
Copy link
Member

hmm, the next travis builds have the same (but strange that for the PR it had not this issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO SQL to_sql, read_sql, read_sql_query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants