Package: dias
What is Dias?Dias is an automatic rewriter ofpandascode for Jupyter (IPython) notebooks. It rewritespandascode to semantically equivalent but faster versions, on-the-fly, transparently and correctly. Dias is extremely lightweight and it will incur virtually no extra runtime or memory overheads. At the same time, Dias can provide100x or even 1000x speedups(see example below).Dias identifies rewrite opportunities automatically and leaves the rest of the code untouched, so you do not have to change a single line of yourpandascode to use it.Quick StartQuickstart Colab NotebookThe fastest way to get started is to play around with ourQuickstart Google Colab notebook. Otherwise, you can follow the documentation here to experiment locally.Vanilla PandasWith Diasimportpandasaspdimportnumpyasnprand_arr=np.random.rand(2_500_000,20)df=pd.DataFrame(rand_arr)%%timedefweighted_rating(x,m=50,C=5.6):v=x[0]R=x[9]return(v/(v+m)*R)+(m/(m+v)*C)df.apply(weighted_rating,axis=1)importpandasaspd# Import Dias. Keep everything# else the same.importdias.rewriterimportnumpyasnprand_arr=np.random.rand(2_500_000,20)df=pd.DataFrame(rand_arr)%%timedefweighted_rating(x,m=50,C=5.6):v=x[0]R=x[9]return(v/(v+m)*R)+(m/(m+v)*C)df.apply(weighted_rating,axis=1)Original: 10.3sRewritten: 48.4msSpeedup: 212xInstallationpip install diasUsageMake sure that you are using a Jupyter/IPython notebook.First import the package... That's it!importdias.rewriterExamplesOurQuickstart notebookcontains many examples in a single place. You can also see ourexamples directorywhich lists self-contained examples that showcase different use cases Dias.FAQHow lightweight is Dias?Dias is extremely lightweight. In terms of memory overheads, anything that runs with vanillapandas, runs with Dias enabled too. Dias is just a code rewriter, so it does not alter the waypandasstores data and its internal state is minimal.Dias' runtime overheads are minimal too. Inour experiments, the maximum overhead of Dias is 23ms. You may also want to take a look atthis example, where even though the original cell is quick, it is still worth using Dias.Can I inspect the rewritten version?Yes. Dias' output is standard Python code, and so, for example, you do not need to know anything about Dias to know why you got a speedup. Similarly, you can just copy Dias' output and use it as any other Python code.To inspect the rewritten version, add the comment# DIAS_VERBOSEat the beginning of your cell (right after any magic functions). Seethis example.Is Dias a replacement forpandas?No (which inherently means Dias does not suffer from lack of API support). Dias is a rewriter, which inspects and possibly rewritespandascode.Does Dias work with a standard Python interpreter?No. Dias currently uses IPython features.When does Dias rewrite code?Dias looks for certain patterns, and upon recognizing one, it rewrites the code to a faster version. Thus, Dias will rewrite the code if it contains one of the patterns it is programmed to look for. Considerthis example. One pattern Dias looks for is any expression followed bysort_values(), followed byhead(). Upon recognizing this pattern, it rewrites the code to usensmallest(). You can take a look atthe paperfor more information.Dias is still under early but active development, so expect more patterns to be added soon!Is Dias probabilistic? Is Dias an assistant?No and no. Dias is not probabilistic; if it rewrites code, it is always correct (barring implementation bugs). Dias is also not intended to be an assistant. First, it's intended to be more quiet than an assistant. If Dias does its job correctly, then you should never have to think of it. Second, while you can inspect the rewritten code, Dias does not offer any explanations of why the rewritten version is faster.How to contributeDias is an ongoing research project by theADAPT group @ UIUC. You can help us by sending us notebooks that you want to speed up and we will our best to make Dias do it automatically (send us an emailwith either the notebook or Colab link)! Moreover, if you are aware of a pattern that can be rewritten to a faster version, please consider submitting an issue. You can useour template.We also welcome feedback from all backgrounds, including industry specialists, data analysts and academics. Please reach out tosb54@illinois.eduto share your opinion!