Skip to content

Instantly share code, notes, and snippets.

@yassineAlouini
Created November 15, 2017 07:54
Show Gist options
  • Save yassineAlouini/3bcbb2dda8ac4495e872d1a091674f35 to your computer and use it in GitHub Desktop.
Save yassineAlouini/3bcbb2dda8ac4495e872d1a091674f35 to your computer and use it in GitHub Desktop.
Log shape and dtypes of a DataFrame
from functools import wraps
from logs import logger
# Two decorator to log the shape and dtypes of a DataFrame
# Inspired from here: https://tomaugspurger.github.io/method-chaining
def log_shape(func):
@wraps(func)
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
logger.debug("%s,%s" % (func.__name__, result.shape))
return result
return wrapper
def log_dtypes(func):
@wraps(func)
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
logger.debug("%s,%s" % (func.__name__, result.dtypes))
return result
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment