Dataflow Kernel Tutorial

Controlling Output references

In the Dataflow Kernel there are several different ways to export your variables into the current namespace that you’re working in. Any unnamed type will simply be given a persistent identifier that matches the persistent cell identifier that the input is given.

In [e90038]:
2+3
Out[e90038]:
5

You can also give an output a tag by assigning a name to it, as long as the variable has a name we can just export that into the namespace.

In [aabe16]:
a = 3
a:
3

All names are considered persistent throughout the notebook, this means if you try and reassign it in a different cell you’ll get an error however, this can be resolved by simply deleting that cell and you’ll be able to redefine that name in any other cell.

In [f2146e]:
a = 4
---------------------------------------------------------------------------
DuplicateNameError                        Traceback (most recent call last)
DuplicateNameError: name 'a' has already been defined in Cell 'aabe16'

You can also assign multiple variables at once as long as you pass multiple references.

In [cff2e4]:
c,d = 3,4
c:
3
d:
4
In [b7f27b]:
e,f = 5,6
e,f
e:
5
f:
6

In the case of mixed named and unnamed variables the named variables will be pulled out by their variable names and any unnamed variables will be given the ability to be referenced through bracket notation.

In [aaa071]:
g,h = 5,6
g,h,[2,3]
g:
5
h:
6
Out[aaa071][2]:
[2, 3]

Output Magics

Since a user might want to split out a dictionary into multiple variables we’ve provided methods for that.

NOTE: In versions of Python below 3.6 tags are not guaranteed to be in order as dict keys have no guaranteed ordering and if you desire your keys to be in order we suggest the user of ``OrderedDict``.

In [fff27b]:
%split_out {'j':1,'k':1}
j:
1
k:
1

Accessing Outputs

The Dataflow kernel allows for several different methods of accessing exported variables in the notebook. Completion is enabled for only the last cell in the most current revision, despite this cells and tags that have been exported can all be autocompleted by using the completer.

In [c3f778]:
m = 4
m:
4

_ + <tab> produces

In [d04d7a]:
m
Out[d04d7a]:
4
In [f2cc87]:
n,o = 1,2
n:
1
o:
2

When a cell has multiple tags the completer will produce a tuple of the outputs

In [f21db2]:
(n,o)
Out[f21db2]:
(1, 2)

A cell can also still be addressed as it’s original output tag if desired but this behavior is discouraged unless the user needs to reference outputs this way.

In the example below typing f2c and hitting <tab> will result in the following

In [def65e]:
Out[f2cc87]
Out[def65e]:
(1, 2)

Auto-Parse Library functionality

To make life easier on users we came to the conclusion that libraries should be parsed out at a local level because writing extra code to specifically export libraries slows users down.

So even when you write only assignments the library will be parsed out and become attached to that cell.

In [f2e1a8]:
import sys
p = 3
sys:
<module 'sys' (built-in)>
p:
3

However, when you access the cell or try to reference it, it will perform in the same way you expected before so it doesn’t become a problem when referencing objects.

In [efd9e7]:
Out[f2e1a8]
Out[efd9e7]:
3

It also performs the same way when you have multiple tags but is instead referenced as a tuple.

In [bcaf80]:
import os
q,r = 1,2
os:
<module 'os' from '/home/colin/anaconda3/envs/noglobals/lib/python3.6/os.py'>
q:
1
r:
2
In [f0a682]:
Out[bcaf80]
Out[f0a682]:
(1, 2)