# 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
                    hsh)
        return '%s [%s]'%(self._remove_hashes(existing_name),
                    hsh)

    def depends_on_y(self):
        if hasattr(self, '_train'):
            return True
        return any([f.depends_on_y() for f in self.features])

    def depends_on_other_x(self):
        if hasattr(self, '_prepare'):
            return True
        return any([f.depends_on_other_x() for f in self.features])

    def build(self, data, prep_index=None, train_index=None):
        if prep_index is None:
            prep_index = data.index
        if train_index is None:
            train_index = data.index
        datas = []
        fitted_features = []
        for feature in self.features:
            feature_data, ff = feature.build(data, prep_index, train_index)
            datas.append(feature_data)
            fitted_features.append(ff)
        ff = FittedFeature(self,
                           prep_index=prep_index,
                           train_index=train_index,
                           inner_fitted_features=fitted_features)
        ff.prepped_data = self.prepare([reindex_safe(d, prep_index) for d in datas])

# 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

                    hsh)
        return '%s [%s]'%(self._remove_hashes(existing_name),
                    hsh)

    def depends_on_y(self):
        if hasattr(self, '_train'):
            return True
        return any([f.depends_on_y() for f in self.features])

    def depends_on_other_x(self):
        if hasattr(self, '_prepare'):
            return True
        return any([f.depends_on_other_x() for f in self.features])

    def build(self, data, prep_index=None, train_index=None):
        if prep_index is None:
            prep_index = data.index
        if train_index is None:
            train_index = data.index
        datas = []
        fitted_features = []
        for feature in self.features:
            feature_data, ff = feature.build(data, prep_index, train_index)
            datas.append(feature_data)
            fitted_features.append(ff)
        ff = FittedFeature(self,
                           prep_index=prep_index,
                           train_index=train_index,
                           inner_fitted_features=fitted_features)
        ff.prepped_data = self.prepare([reindex_safe(d, prep_index) for d in datas])

        ff.trained_data = self.train([reindex_safe(d, train_index) for d in datas])