+DI, positive directional moving index

        :param df: data
        :param windows: range
        :return:
328532
def _get_pdi(cls, df, windows):
        
        window = cls.get_only_one_positive_int(windows)
        pdm_column = 'pdm_{}'.format(window)
        tr_column = 'atr_{}'.format(window)
        pdi_column = 'pdi_{}'.format(window)
        df[pdi_column] = df[pdm_column] / df[tr_column] * 100
        return df[pdi_column]
415112
def preprocess(df):
    """"""

    def process_row(idx_row):
        idx, row = idx_row

        # press-press latency
        tau = 1000 * row[4::3].astype(float).values
        tau = np.r_[np.median(tau), tau]

        # duration
        duration = 1000 * row[3::3].astype(float).values

        keyname = list('.tie5Roanl') + ['enter']

        return pd.DataFrame.from_items([
            ('user', [row['subject']] * 11),
            ('session', [row['sessionIndex'] * 100 + row['rep']] * 11),
            ('tau', tau),
            ('duration', duration),
            ('event', keyname)
        ])

    df = pd.concat(map(process_row, df.iterrows())).set_index(['user', 'session'])
    return df
498283
def _get_mstd(cls, df, column, windows):
        
        window = cls.get_only_one_positive_int(windows)
        column_name = '{}_{}_mstd'.format(column, window)
        df[column_name] = df[column].rolling(min_periods=1, window=window,
                                             center=False).std()
1030791
def idxmax(self, **kwargs):
        
        if self._is_transposed:
            kwargs["axis"] = kwargs.get("axis", 0) ^ 1
            return self.transpose().idxmax(**kwargs)

        axis = kwargs.get("axis", 0)
        index = self.index if axis == 0 else self.columns

        def idxmax_builder(df, **kwargs):
            if axis == 0:
                df.index = index
            else:
                df.columns = index
            return df.idxmax(**kwargs)

        func = self._build_mapreduce_func(idxmax_builder, **kwargs)
        return self._full_axis_reduce(axis, func)
373105
def invert_dataframe_axis(fct):
    '''
    
    '''
    def inner(*args, **kwargs):
        df_to_invert = fct(*args, **kwargs)
        return pd.DataFrame(df_to_invert.to_dict().values(),
                            index=df_to_invert.to_dict().keys())
    return inner
713873
def multi_index_df_to_component_dfs(multi_index_df, rid="rid", cid="cid"):
    

    # Id level of the multiindex will become the index
    rids = list(multi_index_df.index.get_level_values(rid))
    cids = list(multi_index_df.columns.get_level_values(cid))

    # It's possible that the index and/or columns of multi_index_df are not
    # actually multi-index; need to check for this and there are more than one level in index(python3)
    if isinstance(multi_index_df.index, pd.MultiIndex):

        # check if there are more than one levels in index (python3)
        if len(multi_index_df.index.names) > 1:

            # If so, drop rid because it won't go into the body of the metadata
            mi_df_index = multi_index_df.index.droplevel(rid)

            # Names of the multiindex levels become the headers
            rhds = list(mi_df_index.names)

            # Assemble metadata values
            row_metadata = np.array([mi_df_index.get_level_values(level).values for level in list(rhds)]).T

        # if there is one level in index (python3), then rhds and row metadata should be empty
        else:
            rhds = []
            row_metadata = []

    # If the index is not multi-index, then rhds and row metadata should be empty
    else:
        rhds = []
        row_metadata = []

    # Check if columns of multi_index_df are in fact multi-index
    if isinstance(multi_index_df.columns, pd.MultiIndex):

        # Check if there are more than one levels in columns(python3)
        if len(multi_index_df.columns.names) > 1:

            # If so, drop cid because it won't go into the body of the metadata
            mi_df_columns = multi_index_df.columns.droplevel(cid)

            # Names of the multiindex levels become the headers
            chds = list(mi_df_columns.names)

            # Assemble metadata values
            col_metadata = np.array([mi_df_columns.get_level_values(level).values for level in list(chds)]).T

        # If there is one level in columns (python3), then rhds and row metadata should be empty
        else:
            chds = []
            col_metadata = []
    # If the columns are not multi-index, then rhds and row metadata should be empty
    else:
        chds = []
        col_metadata = []

    # Create component dfs
    row_metadata_df = pd.DataFrame.from_records(row_metadata, index=pd.Index(rids, name="rid"), columns=pd.Index(rhds, name="rhd"))
    col_metadata_df = pd.DataFrame.from_records(col_metadata, index=pd.Index(cids, name="cid"), columns=pd.Index(chds, name="chd"))
    data_df = pd.DataFrame(multi_index_df.values, index=pd.Index(rids, name="rid"), columns=pd.Index(cids, name="cid"))

    return data_df, row_metadata_df, col_metadata_df
1133924
def idxmin(self, **kwargs):
        
        if self._is_transposed:
            kwargs["axis"] = kwargs.get("axis", 0) ^ 1
            return self.transpose().idxmin(**kwargs)

        axis = kwargs.get("axis", 0)
        index = self.index if axis == 0 else self.columns

        def idxmin_builder(df, **kwargs):
            if axis == 0:
                df.index = index
            else:
                df.columns = index
            return df.idxmin(**kwargs)

        func = self._build_mapreduce_func(idxmin_builder, **kwargs)
        return self._full_axis_reduce(axis, func)
682173
def index_bounds(x):
    """"""
    if isinstance(x, (pd.DataFrame, pd.Series)):
        return x.iloc[0], x.iloc[-1]
    else:
        return x[0], x[-1]
113804
def _get_sma(cls, df, column, windows):
        
        window = cls.get_only_one_positive_int(windows)
        column_name = '{}_{}_sma'.format(column, window)
        df[column_name] = df[column].rolling(min_periods=1, window=window,
                                             center=False).mean()
1172082
def windowed_run_events_1d(arr, window):
    
    v, rl, pos = rle_1d(arr)
    return (v * rl >= window).sum()
457397
def moving_average(self, window, method=SIMPLE):
        ''''''
        if len(self.points) < window:
            raise ArithmeticError('Not enough points for moving average')
        numpy = LazyImport.numpy()
        if method == TimeSeries.SIMPLE:
            weights = numpy.ones(window) / float(window)
        ma_x = self.timestamps[window-1:]
        ma_y = numpy.convolve(self.values, weights)[window-1:-(window-1)].tolist()
        return TimeSeries(zip(ma_x, ma_y))
987984
def dfbool2intervals(df,colbool):
    
    df.index=range(len(df))
    intervals=bools2intervals(df[colbool])
    for intervali,interval in enumerate(intervals):
        df.loc[interval[0]:interval[1],f'{colbool} interval id']=intervali
        df.loc[interval[0]:interval[1],f'{colbool} interval start']=interval[0]
        df.loc[interval[0]:interval[1],f'{colbool} interval stop']=interval[1]
        df.loc[interval[0]:interval[1],f'{colbool} interval length']=interval[1]-interval[0]+1
        df.loc[interval[0]:interval[1],f'{colbool} interval within index']=range(interval[1]-interval[0]+1)    
    df[f'{colbool} interval index']=df.index    
    return df
783530
def df2unstack(df,coln='columns',idxn='index',col='value'):
    
    return dmap2lin(df,idxn=idxn,coln=coln,colvalue_name=col)
588828
function (formula, direction, delta) {
      var type,
          counter;

      // left, right -> col
      if (['left', 'right'].indexOf(direction) !== -1) {
        type = 'col';
      } else if (['up', 'down'].indexOf(direction) !== -1) {
        type = 'row'
      }

      // down, up -> row
      if (['down', 'right'].indexOf(direction) !== -1) {
        counter = delta * 1;
      } else if(['up', 'left'].indexOf(direction) !== -1) {
        counter = delta * (-1);
      }

      if (type && counter) {
        return formula.replace(/(\$?[A-Za-z]+\$?[0-9]+)/g, function (match) {

          var alpha = instance.utils.getCellAlphaNum(match).alpha;

          var fixedCol = alpha[0] === '$' || false,
              fixedRow = alpha[alpha.length - 1] === '$' || false;

          if (type === 'row' && fixedRow) {
            return match;
          }

          if (type === 'col' && fixedCol) {
            return match;
          }

          return (type === 'row' ? instance.utils.changeRowIndex(match, counter) : instance.utils.changeColIndex(match, counter));
        });
      }

      return formula;
    }
1224138
def forward(self, X):
        
        return self.W(X).sum(dim=1) + self.b
198603
def rolling_window(array, axis, window, center, fill_value):
    
    if isinstance(array, dask_array_type):
        return dask_array_ops.rolling_window(
            array, axis, window, center, fill_value)
    else:  # np.ndarray
        return nputils.rolling_window(
            array, axis, window, center, fill_value)
350070
def rolling(self, window, min_periods=None, center=False, win_type=None, on=None, axis=0, closed=None):
        
        kwds = {
            "window": window,
            "min_periods": min_periods,
            "center": center,
            "win_type": win_type,
            "on": on,
            "axis": axis,
            "closed": closed,
        }
        return Rolling(self._obj, self._npartitions, self._dask_threshold, self._scheduler, self._progress_bar, **kwds)