Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelgugino/554db0656cd1b5a21da22da58bf5af99 to your computer and use it in GitHub Desktop.
Save michaelgugino/554db0656cd1b5a21da22da58bf5af99 to your computer and use it in GitHub Desktop.
How to build anything with cython
#mylib.pyx
import pandas as pd
df = pd.DataFrame({ 'A' : 1.,
'B' : pd.Timestamp('20130102'),
'C' : pd.Series(1, index=list(range(4)), dtype='float32'),
'D' : pd.Series([1, 2, 1, 2], dtype='int32'),
'E' : pd.Categorical(["test", "train", "test", "train"]),
'F' : 'foo' })
#setup.py
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("mylib.pyx")
)
#run on cli:
python setup.py build_ext --inplace
#usemylib.py
import mylib
print mylib.df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment