Last active
August 29, 2015 14:21
-
-
Save komsit37/1763ecb0547356058c24 to your computer and use it in GitHub Desktop.
ipython magic function to call q cell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from IPython.core.magic import (register_cell_magic) | |
| from qpython import qconnection | |
| @register_cell_magic | |
| def q(con, cell=None): | |
| """ | |
| execute q statements in jupyter cell. Required qpython https://github.com/exxeleron/qPython | |
| :param con: connection string (default 'localhost:5555') | |
| :type con: str | |
| :returns: result is saved to global 'qdat' or can be accessed with _ | |
| :rtype: dataframe | |
| """ | |
| global qdat | |
| if con == "": | |
| con = "localhost:5555" | |
| tokens = con.split(':') | |
| f = lambda x: tokens[x] if len(tokens)>x else None | |
| h = qconnection.QConnection(host=f(0), port=int(f(1)), username=f(2), password=f(3)) | |
| h.open() | |
| s = cell.encode('ascii') | |
| qdat = h(s, pandas = True) | |
| h.close() | |
| print con + '| returns', qdat.shape | |
| return qdat |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
required qpython https://github.com/exxeleron/qPython