koaning / memo

Decorators that logs stats.
https://koaning.github.io/memo/getting-started.html
MIT License
103 stars 9 forks source link

Are contributions okay? #16

Closed FedeClaudi closed 3 years ago

FedeClaudi commented 3 years ago

Hi,

This looks great, thanks for making it and sharing it. I will most likely use it in my work. I was wandering if contributions are welcome (there's no license and I didn't see anything about in the docs).

In particular I was thinking of adding the option to use the great Rich library to print nicely formatted tables. So in alternative to

{"class_size": 5, "n_sim": 1000, "est_proba": 0.024, "time_taken": 0.0004899501800537109}
{"class_size": 5, "n_sim": 1000000, "est_proba": 0.027178, "time_taken": 0.19407916069030762}
{"class_size": 10, "n_sim": 1000, "est_proba": 0.104, "time_taken": 0.000598907470703125}
{"class_size": 10, "n_sim": 1000000, "est_proba": 0.117062, "time_taken": 0.3751380443572998}
{"class_size": 20, "n_sim": 1000, "est_proba": 0.415, "time_taken": 0.0009679794311523438}
{"class_size": 20, "n_sim": 1000000, "est_proba": 0.411571, "time_taken": 0.7928380966186523}
{"class_size": 30, "n_sim": 1000, "est_proba": 0.703, "time_taken": 0.0018239021301269531}
{"class_size": 30, "n_sim": 1000000, "est_proba": 0.706033, "time_taken": 1.1375510692596436}

to have something like this from pyinspect: image

Let me know if you'd like to receive a PR about this!

koaning commented 3 years ago

Technically, you can already use:

from memo import memfunc 
from rich import print 

@memfunc(callback=print)
def func(foo):
    ...

But this is not a table.

For a nicely formatted table to standard out we do need the entire dataset, no? Can you print a table row by row in rich?

FedeClaudi commented 3 years ago

I see, I clearly need to dig deeper into how memo works.

Can you print a table row by row in rich?

Not out of the box I don't think but it can be hacked together.

koaning commented 3 years ago

I'm open to a utility method, something like print_pretty_table, that accepts a list of dictionaries as input and outputs a pretty table. It's something that could also be useful from the commandline.

FedeClaudi commented 3 years ago

okay, once I start using memo I will see if I can make something useful. Thanks again for making memo, looks awesome

koaning commented 3 years ago

It deserves mentioning though that you can already use pd.DataFrame(data). Given that pandas already supports a pretty layout, would it really make sense to also offer a rich view?

koaning commented 3 years ago

I'll close the issue for now. Feel free to re-open if need be.