# Path: ramp/store.py
# class Storable(object):
#     
#     def to_pickle(self, path):
#         dumppickle(self, path)
# 
#     @classmethod
#     def from_pickle(cls, path):
#         obj = loadpickle(path)
#         assert type(obj) == cls
#         return obj
# 
#     def to_string(self):
#         pass
# 
#     def to_hdf5(self, path):
#         pass
# 
#     def to_hdf5_or_pickle(self, path):
#         pass
# 
# Path: ramp/utils.py
# def _pprint(params):
# def pprint_scores(scores):
# def shuffle_df(df):
# def get_np_hash(obj):
# def get_np_hashable(obj):
# def key_from_index(idx):
# def get_single_column(df):
# def reindex_safe(df, idx):
# def stable_repr(obj):
# def is_categorical(series):
# def cosine(vec1, vec2):
# def clean_url(u):
# def normalize(s):
# def tokenize(s):
# def tokenize_keep_all(s):
# def tokenize_with_sentinels(s):
# def bag_of_words(s):
# def add_terms(s):
# 
# Path: ramp/utils.py
# def _pprint(params):
#     """prints object state in stable manner"""
#     params_list = list()
#     line_sep = ','
#     for i, (k, v) in enumerate(sorted(params.iteritems())):
#         if type(v) is float:
#             # use str for representing floating point numbers
#             # this way we get consistent representation across
#             # architectures and versions.
#             this_repr = '%s=%.10f' % (k, v)
#         else:
#             # use repr of the rest
#             this_repr = '%s=%r' % (k, v)
#         params_list.append(this_repr)
# 
#     lines = ','.join(params_list)
#     return lines
# 
# def get_np_hashable(obj):
#     try:
#         return np.getbuffer(obj)
#     except TypeError:
#         return np.getbuffer(obj.flatten())
# 
# def key_from_index(idx):
#     return get_np_hash(idx.values)
# 
# def get_single_column(df):
#     if len(df.columns) != 1:
#         raise ValueError("More than one column")
#     return df[df.columns[0]]
# 
# def stable_repr(obj):
#     state = _pprint(obj.__getstate__())
#     # HACK: replace 'repr's that contain object id references
#     state = re_object_repr.sub('>', state)
#     return '%s(%s)' % (
#             obj.__class__.__name__,
#             state)
# 
# def reindex_safe(df, idx):
#     if df.index.equals(idx):
#         # Don't make unnecessary copy of data
#         df_idx = df
#     else:
#         df_idx = df.loc[idx]
#         # ditto
#         assert len(df_idx) == len(idx)
#     return df_idx


from hashlib import md5
from pandas import Series, DataFrame, concat
from ramp.store import Storable
from ramp import utils
from ramp.utils import (_pprint, get_np_hashable, key_from_index,
                        get_single_column, stable_repr, reindex_safe)
import math
import random
import re
import numpy as np
import combo
            levels = zip(levels, range(len(levels)))
        return levels

    def _apply(self, data, fitted_feature):
        levels = fitted_feature.prepped_data
        mapping = dict(levels)
        return data.applymap(mapping.get)

    def get_name(self, factor):
        factors = self.get_prep_data()
        inverse = dict([(v,k) for k,v in factors])
        return inverse.get(factor)


class AsFactorIndicators(Feature):
    """
    Maps nominal values to indicator columns. So
    a column with values ['good', 'fair', 'poor'],
    would be mapped to three indicator columns
    if include_all is True otherwise two columns (the
    third implied by zeros on the other two columns)
    """
    def __init__(self, feature, levels=None, include_all=True, only_if_categorical=False):
        super(AsFactorIndicators, self).__init__(feature)
        self.levels = levels
        self.include_all = include_all
        self.only_if_categorical = only_if_categorical

    def _prepare(self, data):
        try:

# Path: ramp/store.py
# class Storable(object):
#     
#     def to_pickle(self, path):
#         dumppickle(self, path)
# 
#     @classmethod
#     def from_pickle(cls, path):
#         obj = loadpickle(path)
#         assert type(obj) == cls
#         return obj
# 
#     def to_string(self):
#         pass
# 
#     def to_hdf5(self, path):
#         pass
# 
#     def to_hdf5_or_pickle(self, path):
#         pass
# 
# Path: ramp/utils.py
# def _pprint(params):
# def pprint_scores(scores):
# def shuffle_df(df):
# def get_np_hash(obj):
# def get_np_hashable(obj):
# def key_from_index(idx):
# def get_single_column(df):
# def reindex_safe(df, idx):
# def stable_repr(obj):
# def is_categorical(series):
# def cosine(vec1, vec2):
# def clean_url(u):
# def normalize(s):
# def tokenize(s):
# def tokenize_keep_all(s):
# def tokenize_with_sentinels(s):
# def bag_of_words(s):
# def add_terms(s):
# 
# Path: ramp/utils.py
# def _pprint(params):
#     """prints object state in stable manner"""
#     params_list = list()
#     line_sep = ','
#     for i, (k, v) in enumerate(sorted(params.iteritems())):
#         if type(v) is float:
#             # use str for representing floating point numbers
#             # this way we get consistent representation across
#             # architectures and versions.
#             this_repr = '%s=%.10f' % (k, v)
#         else:
#             # use repr of the rest
#             this_repr = '%s=%r' % (k, v)
#         params_list.append(this_repr)
# 
#     lines = ','.join(params_list)
#     return lines
# 
# def get_np_hashable(obj):
#     try:
#         return np.getbuffer(obj)
#     except TypeError:
#         return np.getbuffer(obj.flatten())
# 
# def key_from_index(idx):
#     return get_np_hash(idx.values)
# 
# def get_single_column(df):
#     if len(df.columns) != 1:
#         raise ValueError("More than one column")
#     return df[df.columns[0]]
# 
# def stable_repr(obj):
#     state = _pprint(obj.__getstate__())
#     # HACK: replace 'repr's that contain object id references
#     state = re_object_repr.sub('>', state)
#     return '%s(%s)' % (
#             obj.__class__.__name__,
#             state)
# 
# def reindex_safe(df, idx):
#     if df.index.equals(idx):
#         # Don't make unnecessary copy of data
#         df_idx = df
#     else:
#         df_idx = df.loc[idx]
#         # ditto
#         assert len(df_idx) == len(idx)
#     return df_idx


# Path: ramp/features/base.py
from hashlib import md5
from pandas import Series, DataFrame, concat
from ramp.store import Storable
from ramp import utils
from ramp.utils import (_pprint, get_np_hashable, key_from_index,
                        get_single_column, stable_repr, reindex_safe)
import math
import random
import re
import numpy as np
import combo

            levels = zip(levels, range(len(levels)))
        return levels

    def _apply(self, data, fitted_feature):
        levels = fitted_feature.prepped_data
        mapping = dict(levels)
        return data.applymap(mapping.get)

    def get_name(self, factor):
        factors = self.get_prep_data()
        inverse = dict([(v,k) for k,v in factors])
        return inverse.get(factor)


class AsFactorIndicators(Feature):
    """
    Maps nominal values to indicator columns. So
    a column with values ['good', 'fair', 'poor'],
    would be mapped to three indicator columns
    if include_all is True otherwise two columns (the
    third implied by zeros on the other two columns)
    """
    def __init__(self, feature, levels=None, include_all=True, only_if_categorical=False):
        super(AsFactorIndicators, self).__init__(feature)
        self.levels = levels
        self.include_all = include_all
        self.only_if_categorical = only_if_categorical

    def _prepare(self, data):
        try:

            data = get_single_column(data)