ipython-sql
ipython-sql copied to clipboard
Exception with `%config SqlMagic.autopandas=True`
%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().
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)
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
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.
Thanks gcbeltramini, ipython-sql v 0.3.9 work well !
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
Once installing 0.3.9, a load_ext sql produces an error of ModuleNotFoundError