|
24 | 24 | import os
|
25 | 25 | import re
|
26 | 26 | import numpy as np
|
| 27 | +import operator |
27 | 28 | import pandas as pd
|
28 | 29 | from functools import reduce
|
29 | 30 | from collections import deque, OrderedDict
|
@@ -295,7 +296,7 @@ def spike_regressors(
|
295 | 296 | mask[metric] = set(np.where(data[metric] < threshold)[0])
|
296 | 297 | elif criterion == ">":
|
297 | 298 | mask[metric] = set(np.where(data[metric] > threshold)[0])
|
298 |
| - mask = reduce((lambda x, y: x | y), mask.values()) |
| 299 | + mask = reduce(operator.or_, mask.values()) |
299 | 300 |
|
300 | 301 | for lag in lags:
|
301 | 302 | mask = set([m + lag for m in mask]) | mask
|
@@ -362,7 +363,7 @@ def temporal_derivatives(order, variables, data):
|
362 | 363 | variables_deriv[o] = ["{}_derivative{}".format(v, o) for v in variables]
|
363 | 364 | data_deriv[o] = np.tile(np.nan, data[variables].shape)
|
364 | 365 | data_deriv[o][o:, :] = np.diff(data[variables], n=o, axis=0)
|
365 |
| - variables_deriv = reduce((lambda x, y: x + y), variables_deriv.values()) |
| 366 | + variables_deriv = reduce(operator.add, variables_deriv.values()) |
366 | 367 | data_deriv = pd.DataFrame(
|
367 | 368 | columns=variables_deriv, data=np.concatenate([*data_deriv.values()], axis=1)
|
368 | 369 | )
|
@@ -404,7 +405,7 @@ def exponential_terms(order, variables, data):
|
404 | 405 | for o in order:
|
405 | 406 | variables_exp[o] = ["{}_power{}".format(v, o) for v in variables]
|
406 | 407 | data_exp[o] = data[variables] ** o
|
407 |
| - variables_exp = reduce((lambda x, y: x + y), variables_exp.values()) |
| 408 | + variables_exp = reduce(operator.add, variables_exp.values()) |
408 | 409 | data_exp = pd.DataFrame(
|
409 | 410 | columns=variables_exp, data=np.concatenate([*data_exp.values()], axis=1)
|
410 | 411 | )
|
@@ -570,7 +571,7 @@ def _unscramble_regressor_columns(parent_data, data):
|
570 | 571 | var[col].appendleft(c)
|
571 | 572 | else:
|
572 | 573 | var[col].append(c)
|
573 |
| - unscrambled = reduce((lambda x, y: x + y), var.values()) |
| 574 | + unscrambled = reduce(operator.add, var.values()) |
574 | 575 | return data[[*unscrambled]]
|
575 | 576 |
|
576 | 577 |
|
@@ -649,7 +650,7 @@ def parse_formula(model_formula, parent_data, unscramble=False):
|
649 | 650 | (variables[expression], data[expression]) = parse_expression(
|
650 | 651 | expression, parent_data
|
651 | 652 | )
|
652 |
| - variables = list(set(reduce((lambda x, y: x + y), variables.values()))) |
| 653 | + variables = list(set(reduce(operator.add, variables.values()))) |
653 | 654 | data = pd.concat((data.values()), axis=1)
|
654 | 655 |
|
655 | 656 | if unscramble:
|
|
0 commit comments