# 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
# -*- coding: utf-8 -*-
'''
Features: Base
-------

The Base Features module provides a set of abstract base classes and simple
feature definitions (such as Length, Log, Power, etc). The ABC's can be built
upon, such as in the text or combo modules.

These Feature classes allow for chaining and combining features.
'''




available_features = []


class FittedFeature(Storable):

    def __init__(self, feature, train_index, prep_index, prepped_data=None,
                 trained_data=None, inner_fitted_features=None):
        self.feature = feature

        # compute metadata
        self.train_n = len(train_index)
        self.prep_n = len(prep_index)
        self.train_data_key = key_from_index(train_index)

# 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

# -*- coding: utf-8 -*-
'''
Features: Base
-------

The Base Features module provides a set of abstract base classes and simple
feature definitions (such as Length, Log, Power, etc). The ABC's can be built
upon, such as in the text or combo modules.

These Feature classes allow for chaining and combining features.
'''




available_features = []


class FittedFeature(Storable):

    def __init__(self, feature, train_index, prep_index, prepped_data=None,
                 trained_data=None, inner_fitted_features=None):
        self.feature = feature

        # compute metadata
        self.train_n = len(train_index)
        self.prep_n = len(prep_index)
        self.train_data_key = key_from_index(train_index)

        self.prep_data_key = key_from_index(prep_index)