Jeffrey McLarty

  1. Smuggle - Log, catalogue, and move python objects via pickling
  2. Sympa - Symbolic math for pandas
  3. RRSM - Readable run-time state machine
  4. PySter - Python *anywhere
  5. Trump - coming soon...

Smuggle 0.2.0

Log, catalogue, and move python objects via pickling

Coverage Status

In [1]:
from smuggle import Smuggler, Payload # Reduce development costs and downtime!
In [2]:
# Create a safe place to smuggle objects to...
MySmuggler = Smuggler("C:\MyObjectLogFolder")

# Create some picklable objects...
aList = [1,2,3]
aDict = {'a' : 1, 'b' : 2, 'c' : 3}

# Use this in inconvenient code paths to augment logging and errors...
MySmuggler.smuggle(MyList=aList,MyDict=aDict,NoteToSelf="This is cool")

# Send this to an e-mail, log, or the screen. 
print(MySmuggler.passphrases())

import pickle

# NoteToSelf of type 'str' was smuggled at 22:57:51, 2015/03/04
#   'This is cool'
NoteToSelf = pickle.load(open(r"C:\MyObjectLogFolder\NoteToSelf-2015-03-04-22-57-51.smug","rb"))

# MyList of type 'list' was smuggled at 22:57:51, 2015/03/04
#   [1, 2, 3]
MyList = pickle.load(open(r"C:\MyObjectLogFolder\MyList-2015-03-04-22-57-51.smug","rb"))

# MyDict of type 'dict' was smuggled at 22:57:51, 2015/03/04
#   {'a': 1, 'c': 3, 'b': 2}
MyDict = pickle.load(open(r"C:\MyObjectLogFolder\MyDict-2015-03-04-22-57-51.smug","rb"))


In [3]:
# There are a few systematic ways to access the pickled objects
MyPayload = Payload("C:\MyObjectLogFolder")
MyPayload.astimevardict2D()
Out[3]:
{datetime.datetime(2015, 3, 4, 22, 28, 43): {'MyDict': {'a': 1,
   'b': 2,
   'c': 3},
  'MyList': [1, 2, 3],
  'NoteToSelf': 'This is cool'},
 datetime.datetime(2015, 3, 4, 22, 30, 48): {'MyDict': {'a': 1,
   'b': 2,
   'c': 3},
  'MyList': [1, 2, 3],
  'NoteToSelf': 'This is cool'},
 datetime.datetime(2015, 3, 4, 22, 57, 51): {'MyDict': {'a': 1,
   'b': 2,
   'c': 3},
  'MyList': [1, 2, 3],
  'NoteToSelf': 'This is cool'}}

Sympa 0.1.0

Symbolic math for pandas
In [4]:
from sympa import domath
In [5]:
#We need some other stuff to show off sympa
from sympy import *
from sympy.interactive.printing import init_printing
init_printing()
import pandas as pd
In [6]:
#Set up some data (ints, floats, and irrational!)
df = pd.DataFrame({'x' : range(7)})
df['x'] = df.x * 10
df['y'] = df.x * 0.05
df['r'] = pi * df['y'] / 2
df
Out[6]:
x y r
0 0 0.0 0
1 10 0.5 0.25*pi
2 20 1.0 0.5*pi
3 30 1.5 0.75*pi
4 40 2.0 1.0*pi
5 50 2.5 1.25*pi
6 60 3.0 1.5*pi
In [7]:
x,y,r,rn1,x1,xn1,yn1 = symbols('x y r r_-1 x_1 x_-1 y_-1')
f = x + xn1
g = x**y + x*y*3.0 + (x1 * 0.5 + xn1 * pi / (yn1 + 1.0))**2
h = sin(r)
i = sin(r) / cos(rn1 + 1)
In [8]:
f, g, h, i
Out[8]:
$$\left ( x + x_{-1}, \quad 3.0 x y + x^{y} + \left(\frac{\pi x_{-1}}{y_{-1} + 1.0} + 0.5 x_{1}\right)^{2}, \quad \sin{\left (r \right )}, \quad \frac{\sin{\left (r \right )}}{\cos{\left (r_{-1} + 1 \right )}}\right )$$
In [9]:
# This is where the magic happens...
# ...the symbol names link to column names, and the subscripts handle shifts properly.
df['f'] = domath(df,f)
df['g'] = domath(df,g)
df['h'] = domath(df,h)
df['i'] = domath(df,i)
In [10]:
df # Look mom, no lambda!
Out[10]:
x y r f g h i
0 0 0.0 0 NaN NaN 0.000000e+00 NaN
1 10 0.5 0.25*pi 10 118.162278 7.071068e-01 1.308724e+00
2 20 1.0 0.5*pi 30 1371.967615 1.000000e+00 -4.695752e+00
3 30 1.5 0.75*pi 50 2942.914269 7.071068e-01 -8.403222e-01
4 40 2.0 1.0*pi 70 5771.178626 1.224647e-16 -1.253398e-16
5 50 2.5 1.25*pi 90 23220.539991 -7.071068e-01 1.308724e+00
6 60 3.0 1.5*pi 110 NaN -1.000000e+00 -4.695752e+00

RRSM 0.2.0

Readable run-time state machine

Coverage Status

In [3]:
from rrsm import StateMachine

This isn't exactly for iPython Notebook. It's more for prototyping classes in a way that makes it harder to write undocumented code. Just by using this class, you have no choice but to document the states properly.

In [5]:
#Instantiation works with a list of the form ['state', ...]
#or a dictionary of the form {'state' : value, ...}
SM = StateMachine(['cool', 'off', 'on', 'warm']) #Initializes to the first state, "cool".
#checking state works against strings or integers:
SM == 'cool'
Out[5]:
True
In [6]:
#Change the state
SM('warm')
#using attributes to check state:
SM == SM.cool
Out[6]:
False
In [8]:
SM.current_state, SM.current_code
Out[8]:
('warm', 3)

PySter Beta

Python *anywhere

Please see the README, and watch the video below in HD @ vimeo

In [25]:
from IPython.lib.display import VimeoVideo
VimeoVideo(121615286,1056,594)
Out[25]:

Trump 0.1.0

Coming Soon...