if not items:
return {}
py_repr = "cat(..py.repr(list({})))".format(",".join("{0}={0}".format(x) for x in items))
response = self.sos_kernel.get_response(py_repr, ("stream",), name=("stdout",))[0][1]
expr = response["text"]
if to_kernel in ("Python2", "Python3"):
// directly to python3
return "{}\nglobals().update({})".format("from feather import read_dataframe\n" if "read_dataframe" in expr else "", expr)
// to sos or any other kernel
else:
// irkernel (since the new version) does not produce execute_result, only
// display_data
try:
if "read_dataframe" in expr:
// imported to be used by eval
from feather import read_dataframe
// suppress flakes warning
read_dataframe
// evaluate as raw string to correctly handle \\ etc
return eval(expr)
except Exception as e:
self.sos_kernel.warn("Failed to evaluate {!r}: {}".format(expr, e))
return None
After Change
def put_vars(self, items, to_kernel=None):
// first let us get all variables with names starting with sos
response = self.sos_kernel.get_response("whos(r"sos")", ("stream",), name=("stdout",), debug=True)[0][1]
all_vars = [x.strip().split()[0] for x in response["text"].split("\n") if x.strip()]
items += [x for x in all_vars if x.startswith("sos")]
if not items:
return {}
res = {}
for item in items:
py_repr = "__sos__julia_py_repr({})".format(item)
self.sos_kernel.warn("RXPR for {} is {}".format(item, py_repr))
response = self.sos_kernel.get_response(py_repr, ("stream",), name=("stdout",), debug=True)[0][1]
expr = response["text"]
try:
if "read_dataframe" in expr:
// imported to be used by eval
from feather import read_dataframe
// suppress flakes warning
read_dataframe
// evaluate as raw string to correctly handle \\ etc
res[item] = eval(expr)
except Exception as e:
self.sos_kernel.warn("Failed to evaluate {!r}: {}".format(expr, e))
return None
return res