ipython-sql
ipython-sql copied to clipboard
psal backslash error - \d tablename
Running the following:
%sql CREATE TABLE "test" ("col1" TEXT PRIMARY KEY, "col2" INTEGER);
%sql \d test
AttributeError: 'list' object has no attribute 'fetchall'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-28-037c64eb3c47> in <module>()
----> 1 get_ipython().run_line_magic('sql', '\\d test')
/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2093 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2094 with self.builtin_trap:
-> 2095 result = fn(*args,**kwargs)
2096 return result
2097
<decorator-gen-126> in execute(self, line, cell, local_ns)
/usr/local/lib/python3.5/dist-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
<decorator-gen-125> in execute(self, line, cell, local_ns)
/usr/local/lib/python3.5/dist-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
/usr/local/lib/python3.5/dist-packages/sql/magic.py in execute(self, line, cell, local_ns)
93
94 try:
---> 95 result = sql.run.run(conn, parsed['sql'], self, user_ns)
96
97 if result is not None and not isinstance(result, str) and self.column_local_vars:
/usr/local/lib/python3.5/dist-packages/sql/run.py in run(conn, sql, config, user_namespace)
335 _, cur, headers, _ = pgspecial.execute(
336 conn.session.connection.cursor(), statement)[0]
--> 337 result = FakeResultProxy(cur, headers)
338 else:
339 txt = sqlalchemy.sql.text(statement)
/usr/local/lib/python3.5/dist-packages/sql/run.py in __init__(self, cursor, headers)
298
299 def __init__(self, cursor, headers):
--> 300 self.fetchall = cursor.fetchall
301 self.fetchmany = cursor.fetchmany
302 self.rowcount = cursor.rowcount
AttributeError: 'list' object has no attribute 'fetchall'
Same issue, any progress or ideas?
Thanks for the report. Commit 6710de4 fixes this.
Thanks. I get a new error now when running the \d command: TypeError: Argument 'rows' has incorrect type (expected list, got ResultSet)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-037c64eb3c47> in <module>()
----> 1 get_ipython().run_line_magic('sql', '\\d test')
/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2129 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2130 with self.builtin_trap:
-> 2131 result = fn(*args,**kwargs)
2132 return result
2133
<decorator-gen-126> in execute(self, line, cell, local_ns)
/usr/local/lib/python3.5/dist-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
<decorator-gen-125> in execute(self, line, cell, local_ns)
/usr/local/lib/python3.5/dist-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
~/.local/lib/python3.5/site-packages/sql/magic.py in execute(self, line, cell, local_ns)
93
94 try:
---> 95 result = sql.run.run(conn, parsed['sql'], self, user_ns)
96
97 if result is not None and not isinstance(result, str) and self.column_local_vars:
~/.local/lib/python3.5/site-packages/sql/run.py in run(conn, sql, config, user_namespace)
366 resultset = ResultSet(result, statement, config)
367 if config.autopandas:
--> 368 return resultset.DataFrame()
369 else:
370 return resultset
~/.local/lib/python3.5/site-packages/sql/run.py in DataFrame(self)
170 "Returns a Pandas DataFrame instance built from the result set."
171 import pandas as pd
--> 172 frame = pd.DataFrame(self, columns=(self and self.keys) or [])
173 return frame
174
/usr/local/lib/python3.5/dist-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
367 if is_named_tuple(data[0]) and columns is None:
368 columns = data[0]._fields
--> 369 arrays, columns = _to_arrays(data, columns, dtype=dtype)
370 columns = _ensure_index(columns)
371
/usr/local/lib/python3.5/dist-packages/pandas/core/frame.py in _to_arrays(data, columns, coerce_float, dtype)
6282 if isinstance(data[0], (list, tuple)):
6283 return _list_to_arrays(data, columns, coerce_float=coerce_float,
-> 6284 dtype=dtype)
6285 elif isinstance(data[0], collections.Mapping):
6286 return _list_of_dict_to_arrays(data, columns,
/usr/local/lib/python3.5/dist-packages/pandas/core/frame.py in _list_to_arrays(data, columns, coerce_float, dtype)
6359 else:
6360 # list of lists
-> 6361 content = list(lib.to_object_array(data).T)
6362 return _convert_object_array(content, columns, dtype=dtype,
6363 coerce_float=coerce_float)
TypeError: Argument 'rows' has incorrect type (expected list, got ResultSet)
I'm not able to reproduce this in the trunk (commit 6710de4). Can you check which commit you're running?
Thanks, and sorry for the slow response!
same error --
pip3 freeze | grep ipython-sql
ipython-sql==0.3.9