Skip to content

Commit

Permalink
Merge pull request #240 from antoinecarme/numpy_20_and_pandas_30_impact
Browse files Browse the repository at this point in the history
Numpy 20 and pandas 30 impact
  • Loading branch information
antoinecarme authored Jun 16, 2024
2 parents 9d90dba + 7191dfb commit 942b221
Show file tree
Hide file tree
Showing 155 changed files with 10,392 additions and 10,955 deletions.
2 changes: 1 addition & 1 deletion pyaf/TS/Intermittent_Models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def compute_forecast(self, df, alpha, method, horizon_index = 1):
for h in range(horizon_index):
lCounts_df.loc[-(h+1), self.mCycleResidueName] = None
df3 = df1.merge(df2 , how='left', on=('index' , 'index'))
df4 = df3.fillna(method='ffill')
df4 = df3.ffill()
# fill first empty fit data with zero counts (when signal starts with zeros)
i = 0
while(np.isnan(df4.loc[i , 'forecast'])):
Expand Down
4 changes: 2 additions & 2 deletions pyaf/TS/MissingData.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def apply_signal_imputation_method(self, iInputDS, iSignal):
iInputDS[iSignal] = lSignal

elif(lMethod == "PreviousValue"):
lSignal = iInputDS[iSignal].fillna(method='ffill')
lSignal = iInputDS[iSignal].ffill()
# replace the first empty values with the first known value
lSignal = lSignal.fillna(method='bfill')
lSignal = lSignal.bfill()
iInputDS[iSignal] = lSignal

return iInputDS
Expand Down
2 changes: 1 addition & 1 deletion pyaf/TS/Perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def compute_R2(self, signal , estimator):
def compute_LnQ(self, signal , estimator):
min_signal , min_estimator = signal.min() , estimator.min()
# return +inf if the signals are not strictly positive (discard the model)
self.mLnQ = np.Inf
self.mLnQ = np.inf
if(min_signal > 0.0 and min_estimator > 0.0):
log_diff = np.log(estimator) - np.log(signal)
self.mLnQ = np.sum(log_diff * log_diff)
Expand Down
1 change: 0 additions & 1 deletion pyaf/TS/SignalDecomposition_Cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ def fit(self):
self.mEncodedValueDict = self.compute_target_means_by_cycle_value(self.mCycleFrame, self.getCycleName())

self.mCycleFrame[lName + '_enc'] = self.mCycleFrame[lName].map(self.mEncodedValueDict).fillna(self.mDefaultValue)
self.mCycleFrame[lName + '_enc'].fillna(self.mDefaultValue, inplace=True);
self.mCycleFrame[lName + '_NotEncoded'] = self.mCycleFrame[lName];
self.mCycleFrame[lName] = self.mCycleFrame[lName + '_enc'];

Expand Down
4 changes: 2 additions & 2 deletions pyaf/TS/SignalDecomposition_Trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def fit_specific(self):


def compute(self, df):
Y_pred = df[self.mSignal].shift(1).rolling(self.mWindow).mean().fillna(method='bfill');
Y_pred = df[self.mSignal].shift(1).rolling(self.mWindow).mean().ffill();
Y_pred.fillna(self.mMean , inplace=True)
return Y_pred

Expand All @@ -168,7 +168,7 @@ def fit_specific(self):


def compute(self, df):
Y_pred = df[self.mSignal].shift(1).rolling(self.mWindow).median().fillna(method='bfill');
Y_pred = df[self.mSignal].shift(1).rolling(self.mWindow).median().ffill();
Y_pred.fillna(self.mMean , inplace=True)
return Y_pred

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import numpy as np
import pandas as pd

DATA_FREQ = 'H'
PERIODS = ["D" , "H"]
DATA_FREQ = 'h'
PERIODS = ["D" , "h"]
H = 365
N = H * 10
lDateColumn = "Date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import numpy as np
import pandas as pd

DATA_FREQ = 'H'
PERIODS = ["D" , "H"]
DATA_FREQ = 'h'
PERIODS = ["D" , "h"]
H = 365
N = H * 10
lDateColumn = "Date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import numpy as np
import pandas as pd

DATA_FREQ = 'H'
PERIODS = ["T" , "H"]
DATA_FREQ = 'h'
PERIODS = ["min" , "h"]
H = 365
N = H * 10
lDateColumn = "Date"
Expand Down
2 changes: 1 addition & 1 deletion tests/bugs/issue_179/issue_179_cumprod_overflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
N = 1000
lTimeVar = 'Time'
lSignalVar = 'Signal'
df[lTimeVar] = pd.date_range("2018-01-01", periods=N, freq="H")
df[lTimeVar] = pd.date_range("2018-01-01", periods=N, freq="h")
df[lSignalVar] = np.random.random(df.shape[0])
df.info()
print(df.head())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# generate a daily signal covering one year 2016 in a pandas dataframe
N = 365
np.random.seed(seed=1960)
df_train = pd.DataFrame({"Date" : pd.date_range(start="2016-01-25", periods=N, freq='H'),
df_train = pd.DataFrame({"Date" : pd.date_range(start="2016-01-25", periods=N, freq='h'),
"Signal" : (np.arange(N)//40 + np.arange(N) % 21 + np.random.randn(N))})
# print(df_train.head(N))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

b1 = tsds.generate_random_TS(N = 4000 , FREQ = 'D', seed = 0, trendtype = "constant", cycle_length = 24, transform = "None", sigma = 0.1, exog_count = 0);

df = b1.mPastData
df = b1.mPastData.copy()
df[b1.mSignalVar] = df[b1.mName]

lEngine = autof.cForecastEngine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

b1 = tsds.generate_random_TS(N = 4000 , FREQ = 'H', seed = 0, trendtype = "constant", cycle_length = 24, transform = "None", sigma = 0.1, exog_count = 0);

df = b1.mPastData
df = b1.mPastData.copy()
df[b1.mSignalVar] = df[b1.mName]

lEngine = autof.cForecastEngine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

b1 = tsds.generate_random_TS(N = 40000 , FREQ = 'min', seed = 0, trendtype = "constant", cycle_length = 24, transform = "None", sigma = 0.1, exog_count = 0);

df = b1.mPastData
df = b1.mPastData.copy()
df[b1.mSignalVar] = df[b1.mName]

lEngine = autof.cForecastEngine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

b1 = tsds.generate_random_TS(N = 40000 , FREQ = 'S', seed = 0, trendtype = "constant", cycle_length = 24, transform = "None", sigma = 0.1, exog_count = 0);

df = b1.mPastData
df = b1.mPastData.copy()
df[b1.mSignalVar] = df[b1.mName]

lEngine = autof.cForecastEngine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

b1 = tsds.generate_random_TS(N = 4000 , FREQ = 'D', seed = 0, trendtype = "constant", cycle_length = 24, transform = "None", sigma = 0.1, exog_count = 0);

df = b1.mPastData
df = b1.mPastData.copy()
df[b1.mSignalVar] = df[b1.mName]

lEngine = autof.cForecastEngine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

b1 = tsds.generate_random_TS(N = 4000 , FREQ = 'H', seed = 0, trendtype = "constant", cycle_length = 24, transform = "None", sigma = 0.1, exog_count = 0);

df = b1.mPastData
df = b1.mPastData.copy()
df[b1.mSignalVar] = df[b1.mName]

lEngine = autof.cForecastEngine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

b1 = tsds.generate_random_TS(N = 40000 , FREQ = 'min', seed = 0, trendtype = "constant", cycle_length = 24, transform = "None", sigma = 0.1, exog_count = 0);

df = b1.mPastData
df = b1.mPastData.copy()
df[b1.mSignalVar] = df[b1.mName]

lEngine = autof.cForecastEngine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

b1 = tsds.generate_random_TS(N = 40000 , FREQ = 'S', seed = 0, trendtype = "constant", cycle_length = 24, transform = "None", sigma = 0.1, exog_count = 0);

df = b1.mPastData
df = b1.mPastData.copy()
df[b1.mSignalVar] = df[b1.mName]

lEngine = autof.cForecastEngine()
Expand Down
2 changes: 1 addition & 1 deletion tests/bugs/issue_82/issue_82_long_cycles.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
for cyc in lValues:
print("TEST_CYCLES_START", cyc)
b1 = tsds.generate_random_TS(N = 3200 , FREQ = 'H', seed = 0, trendtype = "constant", cycle_length = cyc, transform = "None", sigma = 0.1, exog_count = 0, ar_order=0);
df = b1.mPastData
df = b1.mPastData.copy()
df[b1.mSignalVar] = df[b1.mName]

# df.tail(10)
Expand Down
2 changes: 1 addition & 1 deletion tests/bugs/test_random_exogenous.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# warnings.simplefilter("error")

b1 = tsds.generate_random_TS(N = 160 , FREQ = 'D', seed = 0, trendtype = "constant", cycle_length = 12, transform = "None", sigma = 0.10, exog_count = 1280);
df = b1.mPastData
df = b1.mPastData.copy()
df[b1.mSignalVar] = df[b1.mName]

df.info()
Expand Down
2 changes: 1 addition & 1 deletion tests/croston/test_croston_fpp2_counts_example_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def create_dataset():
lCounts = "0 2 0 1 0 11 0 0 0 0 2 0 6 3 0 0 0 0 0 7 0 0 0 0 0 0 0 3 1 0 0 1 0 1 0 0".split()
lCounts = [float(c) for c in lCounts]
N = len(lCounts)
lDates = pd.date_range(start="2000-01-01", periods=N, freq='m')
lDates = pd.date_range(start="2000-01-01", periods=N, freq='ME')

df = pd.DataFrame({"Date" : lDates, "Signal" : lCounts})
return df
Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_ar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#get_ipython().magic('matplotlib inline')

b1 = tsds.generate_random_TS(N = 320 , FREQ = 'D', seed = 0, trendtype = "constant", cycle_length = 0, transform = "None", sigma = 0.1, ar_order = 12);
df = b1.mPastData
df = b1.mPastData.copy()

df['Signal'] = df[b1.mName]

Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_const_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#get_ipython().magic('matplotlib inline')

b1 = tsds.generate_random_TS(N = 320 , FREQ = 'D', seed = 0, trendtype = "constant", cycle_length = 0, transform = "None", sigma = 0.0, ar_order = 0);
df = b1.mPastData
df = b1.mPastData.copy()

df['Signal'] = df[b1.mName]

Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#get_ipython().magic('matplotlib inline')

b1 = tsds.generate_random_TS(N = 320 , FREQ = 'D', seed = 0, trendtype = "constant", cycle_length = 12, transform = "None", sigma = 0.0);
df = b1.mPastData
df = b1.mPastData.copy()

df['Signal'] = df[b1.mName]

Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_cycles_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
for cyc in lValues:
print("TEST_CYCLES_START", cyc)
b1 = tsds.generate_random_TS(N = 320 , FREQ = 'D', seed = 0, trendtype = "constant", cycle_length = cyc, transform = "None", sigma = 0.1, exog_count = 0);
df = b1.mPastData
df = b1.mPastData.copy()

df['Signal'] = df[b1.mName]

Expand Down
4 changes: 2 additions & 2 deletions tests/perf_MASE_RMSSE/user_test_MAPE.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
def prepare_dataset():
df = pd.read_csv("data/real-life/veturilo.csv", parse_dates=True, usecols=["ts","qnty"], index_col="ts" )
df.qnty.unique()
df.qnty = df.qnty.replace("?", np.NaN).fillna(method='ffill').astype('uint8')
df = df.qnty.resample("H").mean().to_frame()
df.qnty = df.qnty.replace("?", np.nan).ffill().astype('uint8')
df = df.qnty.resample("h").mean().to_frame()

df_predict = df.iloc[:]

Expand Down
4 changes: 2 additions & 2 deletions tests/perf_MASE_RMSSE/user_test_MASE.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
def prepare_dataset():
df = pd.read_csv("data/real-life/veturilo.csv", parse_dates=True, usecols=["ts","qnty"], index_col="ts" )
df.qnty.unique()
df.qnty = df.qnty.replace("?", np.NaN).fillna(method='ffill').astype('uint8')
df = df.qnty.resample("H").mean().to_frame()
df.qnty = df.qnty.replace("?", np.nan).ffill().astype('uint8')
df = df.qnty.resample("h").mean().to_frame()

df_predict = df.iloc[:]

Expand Down
4 changes: 2 additions & 2 deletions tests/perf_MASE_RMSSE/user_test_RMSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
def prepare_dataset():
df = pd.read_csv("data/real-life/veturilo.csv", parse_dates=True, usecols=["ts","qnty"], index_col="ts" )
df.qnty.unique()
df.qnty = df.qnty.replace("?", np.NaN).fillna(method='ffill').astype('uint8')
df = df.qnty.resample("H").mean().to_frame()
df.qnty = df.qnty.replace("?", np.nan).ffill().astype('uint8')
df = df.qnty.resample("h").mean().to_frame()

df_predict = df.iloc[:]

Expand Down
4 changes: 2 additions & 2 deletions tests/perf_MASE_RMSSE/user_test_RMSSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
def prepare_dataset():
df = pd.read_csv("data/real-life/veturilo.csv", parse_dates=True, usecols=["ts","qnty"], index_col="ts" )
df.qnty.unique()
df.qnty = df.qnty.replace("?", np.NaN).fillna(method='ffill').astype('uint8')
df = df.qnty.resample("H").mean().to_frame()
df.qnty = df.qnty.replace("?", np.nan).ffill().astype('uint8')
df = df.qnty.resample("h").mean().to_frame()

df_predict = df.iloc[:]

Expand Down
Loading

0 comments on commit 942b221

Please sign in to comment.