@staticmethod<EOL><INDENT>def hashing_trick(X_in, hashing_method='<STR_LIT>', N=<NUM_LIT:2>, cols=None, make_copy=False):<DEDENT>
try:<EOL><INDENT>if hashing_method not in hashlib.algorithms_available:<EOL><INDENT>raise ValueError('<STR_LIT>' % (<EOL>hashing_method,<EOL>'<STR_LIT:U+002CU+0020>'.join([str(x) for x in hashlib.algorithms_available])<EOL>))<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>try:<EOL><INDENT>_ = hashlib.new(hashing_method)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT><DEDENT>if make_copy:<EOL><INDENT>X = X_in.copy(deep=True)<EOL><DEDENT>else:<EOL><INDENT>X = X_in<EOL><DEDENT>if cols is None:<EOL><INDENT>cols = X.columns.values<EOL><DEDENT>def hash_fn(x):<EOL><INDENT>tmp = [<NUM_LIT:0> for _ in range(N)]<EOL>for val in x.values:<EOL><INDENT>if val is not None:<EOL><INDENT>hasher = hashlib.new(hashing_method)<EOL>if sys.version_info[<NUM_LIT:0>] == <NUM_LIT:2>:<EOL><INDENT>hasher.update(str(val))<EOL><DEDENT>else:<EOL><INDENT>hasher.update(bytes(str(val), '<STR_LIT:utf-8>'))<EOL><DEDENT>tmp[int(hasher.hexdigest(), <NUM_LIT:16>) % N] += <NUM_LIT:1><EOL><DEDENT><DEDENT>return pd.Series(tmp, index=new_cols)<EOL><DEDENT>new_cols = ['<STR_LIT>' % d for d in range(N)]<EOL>X_cat = X.loc[:, cols]<EOL>X_num = X.loc[:, [x for x in X.columns.values if x not in cols]]<EOL>X_cat = X_cat.apply(hash_fn, axis=<NUM_LIT:1>)<EOL>X_cat.columns = new_cols<EOL>X = pd.concat([X_cat, X_num], axis=<NUM_LIT:1>)<EOL>return X<EOL>
A basic hashing implementation with configurable dimensionality/precision

        Performs the hashing trick on a pandas dataframe, `X`, using the hashing method from hashlib
        identified by `hashing_method`.  The number of output dimensions (`N`), and columns to hash (`cols`) are
        also configurable.

        Parameters
        ----------

        X_in: pandas dataframe
            description text
        hashing_method: string, optional
            description text
        N: int, optional
            description text
        cols: list, optional
            description text
        make_copy: bool, optional
            description text

        Returns
        -------

        out : dataframe
            A hashing encoded dataframe.

        References
        ----------
        Cite the relevant literature, e.g. [1]_.  You may also cite these
        references in the notes section above.
        .. [1] Kilian Weinberger; Anirban Dasgupta; John Langford; Alex Smola; Josh Attenberg (2009). Feature Hashing
        for Large Scale Multitask Learning. Proc. ICML.