ipython-sql icon indicating copy to clipboard operation
ipython-sql copied to clipboard

Exception with `%config SqlMagic.autopandas=True`

Open tebeka opened this issue 8 years ago • 6 comments

%config SqlMagic.autopandas=True
%%sql
SELECT 1 AS one
Done.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-19-5d9ee192c327> in <module>()
----> 1 get_ipython().run_cell_magic('sql', '', 'SELECT 1 AS one')

/home/miki/playground/nbext/cenv/lib/python3.5/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2113             magic_arg_s = self.var_expand(line, stack_depth)
   2114             with self.builtin_trap:
-> 2115                 result = fn(magic_arg_s, cell)
   2116             return result
   2117 

<decorator-gen-123> in execute(self, line, cell, local_ns)

/home/miki/playground/nbext/cenv/lib/python3.5/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

<decorator-gen-122> in execute(self, line, cell, local_ns)

/home/miki/playground/nbext/cenv/lib/python3.5/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

/home/miki/playground/nbext/cenv/lib/python3.5/site-packages/sql/magic.py in execute(self, line, cell, local_ns)
     87             result = sql.run.run(conn, parsed['sql'], self, user_ns)
     88 
---> 89             if result and ~isinstance(result, str) and self.column_local_vars:
     90                 #Instead of returning values, set variables directly in the
     91                 #users namespace. Variable names given by column names

/home/miki/playground/nbext/cenv/lib/python3.5/site-packages/pandas/core/generic.py in __nonzero__(self)
    915         raise ValueError("The truth value of a {0} is ambiguous. "
    916                          "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
--> 917                          .format(self.__class__.__name__))
    918 
    919     __bool__ = __nonzero__

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

tebeka avatar Dec 03 '16 15:12 tebeka

Fixed in commit b52e09a.

As of now, PyPI doesn't have this fix, but you can install the latest (and fixed) version with:

$ git clone [email protected]:catherinedevlin/ipython-sql.git
$ cd ipython-sql/
$ pip install .

or

$ pip install git+git://github.com/catherinedevlin/ipython-sql.git

or

$ pip install git+https://github.com/catherinedevlin/ipython-sql.git

(edited after https://github.com/catherinedevlin/ipython-sql/issues/67#issuecomment-298316969)

gcbeltramini avatar Feb 22 '17 18:02 gcbeltramini

I do not believe that this is fixed. The attached notebook is a very simple case - basis SQL works. However, with autopandas=True, you get error. SQL Magic Test Py3.ipynb.zip sql_magic_test_py3

kellington avatar Mar 08 '17 03:03 kellington

Did you install it the way I suggested?

What is the result of running this in the terminal?

pip freeze | grep ipython-sql

The current version is 0.3.9.

gcbeltramini avatar Mar 08 '17 14:03 gcbeltramini

Thanks gcbeltramini, ipython-sql v 0.3.9 work well !

fabricecarles avatar Mar 30 '17 15:03 fabricecarles

I got same error but resolved by this issue. Thank you!

BTW, You can also install the latest version from GitHub like this:

$ pip install git+https://github.com/catherinedevlin/ipython-sql.git

oinume avatar May 01 '17 10:05 oinume

Once installing 0.3.9, a load_ext sql produces an error of ModuleNotFoundError image

jibundit avatar Jul 24 '17 06:07 jibundit