# -*- coding: utf-8 -*-
"""
Created on Wed Jan 06 11:18:21 2021

@author: Fipaniagua

"""

import numpy as np 


def log_difference(df):
    '''
    given a dataframe compute the log difference between days

    params:
        df --> dataframe to wich the diff is compute
    '''
    df = df.apply(np.log)
    df = df.replace([np.inf, -np.inf], 0)
    df = df.fillna(0)
    df = df.diff()
    df = df.dropna()
    return df

def change_granularity(df, granularity):
    '''
    given a dataframe resample to a new days frecuency 

    params:
        df --> dataframe to wich the diff is compute
        granularity --> new frecuency (e.g. "1W" one week "2D" two days)
    '''
    df = df.resample(granularity, label='right', closed="right").sum()
    return df
    