Created
December 4, 2019 22:29
-
-
Save JoshZastrow/e0091f1a87c4a06116b238a1a584b95e to your computer and use it in GitHub Desktop.
decorators for data inspection along pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
import logging | |
def log_shape(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
result = func(*args, **kwargs) | |
logging.info("%s,%s" % (func.__name__, result.shape)) | |
return result | |
return wrapper | |
def log_dtypes(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
result = func(*args, **kwargs) | |
logging.info("%s,%s" % (func.__name__, result.dtypes)) | |
return result | |
return wrapper | |
@log_shape | |
@log_dtypes | |
def load(fp): | |
df = pd.read_csv(fp, index_col=0, parse_dates=True) | |
@log_shape | |
@log_dtypes | |
def update_events(df, new_events): | |
df.loc[new_events.index, 'foo'] = new_events | |
return df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment