koaning/whatlies

Pipe

Closed this issue · 0 comments

I notice that very often I end up writing code that is super similar. Especially when you're comparing two language backends. Suppose I have a spaCy backend and a conveRT backend.

p1 = lang_sp[text].transform(Umap(2)).plot_interactive("umap_0", "umap_1", annot=False).properties(height=200, width=200)
p2 = lang_rt[text].transform(Umap(2)).plot_interactive("umap_0", "umap_1", annot=False).properties(height=200, width=200)
p1 | p2 

It would be much nicer if I could do;

def make_plot(embset):
    return (embset
            .transform(Umap(2))
            .plot_interactive("umap_0", "umap_1", annot=False)
            .properties(height=200, width=200))

p1 = lang_sp[text].pipe(make_plot)
p2 = lang_rt[text].pipe(make_plot)
p1 | p2

A proper .pipe() should allow for less repetition.