cool-RR / PySnooper

Never use print for debugging again
MIT License
16.37k stars 951 forks source link

Deactivate all snooping except explicitly specified "watch"es #247

Open wolthom opened 1 year ago

wolthom commented 1 year ago

Hey There,

First of: Thank you a lot for this awesome package :) It's super useful for ad-hoc debugging of algorithms and data manipulations!

It would be awesome, if I could specify only certain variables, expressions, etc. to snoop on. E.g., consider this minimal, constructed example:

import pandas as pd
import pysnooper

df = pd.DataFrame({"Job": ["3591.", "22226.", "2873.", "3591."]})

@pysnooper.snoop(watch="sub_df.shape")
def clean_df(df):
     sub_df = df
     sub_df = df.groupby("Job").agg("first").reset_index()
     return sub_df

clean_df(df)

In this case, I'd like to see only the expression passed to watch, to see how the DataFrame shape changes throughout the manipulations of some data processing pipeline. Potentially, this could also interoperate really nicely with .pipe or .assign chains in pandas.

My apologies in case I missed this feature in the docs somewhere.

cool-RR commented 1 year ago

Nice idea. If we do this, we could add a keyword argument show_all_variables=True so people could override it to False.

@alexmojaki Do you think this is a good feature to add?

@wolthom If we decide to go forward, will you write the feature including tests and a few lines of documentation?

wolthom commented 1 year ago

@cool-RR This would depend a lot on how large of a PR this becomes / how much guidance someone can give me. Generally speaking, I'm definitely open to contributing this feature!

cool-RR commented 1 year ago

@wolthom Looks like Alex is busy. Feel free to implement, if you wish. If you have any questions, let me know.