# Path: ramp/builders.py
# def build_featureset_safe(features, data, prep_index=None, train_index=None):
#     # check for dupes
#     colnames = set([f.unique_name for f in features])
#     assert len(features) == len(colnames), "Duplicate feature: %s" % colnames
#     if not features:
#         return
#     logging.info("Building %d features... " % len(features))
#     feature_datas = []
#     fitted_features = []
#     for feature in features:
#         d, ff = build_feature_safe(feature, data, prep_index, train_index)
#         feature_datas.append(d)
#         fitted_features.append(ff)
#     logging.info("Done building features")
#     return concat(feature_datas, axis=1), fitted_features
# 
# def build_target_safe(target, data, prep_index=None, train_index=None):
#     y, ff = target.build(data, prep_index, train_index)
#     return get_single_column(y), ff
# 
# def apply_featureset_safe(features, data, fitted_features):
#     assert len(features) == len(fitted_features), "%s, %s" % (len(features),
#                                                               len(fitted_features))
#     feature_datas = []
#     logging.info("Applying %d features to %d data points... " % (len(features), len(data)))
#     for f, ff in zip(features, fitted_features):
#         feature_datas.append(apply_feature_safe(f, data, ff))
#     logging.info("Done applying features")
#     return concat(feature_datas, axis=1)
# 
# def apply_target_safe(target, data, fitted_feature):
#     y = target.apply(data, fitted_feature)
#     return get_single_column(y)
# 
# def filter_data_and_indexes(model_def, data, prep_index=None, train_index=None):
#     for data_filter in model_def.filters:
#         data = data_filter(data)
#     if prep_index is not None:
#         prep_index = data.index & prep_index
#     if train_index is not None:
#         train_index = data.index & train_index
#     return data, prep_index, train_index
# 
# def filter_data(model_def, data):
#     return filter_data_and_indexes(model_def, data)[0]
# 
# Path: ramp/folds.py
# class BasicFolds(object):
# class WatertightFolds(BasicFolds):
# class BinaryTargetFolds(object):
# class BalancedFolds(BinaryTargetFolds):
# class BootstrapFolds(BalancedFolds):
# class BootstrapFoldsByPercentPositive(BootstrapFolds):
# class BootstrapFoldsBySize(BootstrapFolds):
#     def __init__(self, num_folds, data, repeat=1, seed=None):
#     def __iter__(self):
#     def __init__(self, num_folds, data, leakage_column, **kwargs):
#     def __iter__(self):
#     def __init__(self, target, data, seed=None):
#     def compute_folds(self):
#     def build_target(self):
#     def randomize(self):
#     def __iter__(self):
#     def __init__(self, num_folds, target, data, seed=None):
#     def compute_folds(self):
#     def __init__(self, num_folds, target, data,
#                   pos_train=None, pos_test=None, neg_train=None, neg_test=None,
#                   train_pos_percent=None, test_pos_percent=None, train_percent=None,
#                   seed=None):
#     def from_sizes(self):
#     def from_percents(self):
#     def compute_folds(self):
#     def __init__(self, num_folds, target, data,
#                  train_pos_percent, test_pos_percent, train_percent,
#                  seed=None):
#     def __init__(self, num_folds, target, data,
#                  pos_train=None, pos_test=None, neg_train=None, neg_test=None,
#                  seed=None):
# 
# Path: ramp/result.py
# class Result(Storable):
#     def __init__(self, x_train, x_test, y_train, y_test, y_preds, model_def, fitted_model, original_data):
#         """
#         Class for storing the result of a single model fit.
#         """
#         self.x_train = x_train
#         self.x_test = x_test
#         self.y_train = y_train
#         self.y_test = y_test
#         self.y_preds = y_preds
#         self.model_def = model_def
#         self.fitted_model = fitted_model
#         self.original_data = original_data
# 
# 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 key_from_index(idx):
#     return get_np_hash(idx.values)


import pandas as pd
from ramp.builders import (build_featureset_safe,
                           build_target_safe,
                           apply_featureset_safe,
                           apply_target_safe,
                           filter_data_and_indexes,
                           filter_data)
from ramp.folds import make_default_folds
from ramp.result import Result
from ramp.store import Storable
from ramp.utils import key_from_index



class FittedModel(Storable):

    def __init__(self,
                 model_def,
                 fitted_features,
                 fitted_target,
                 fitted_estimator):
        self.model_def = model_def
        self.fitted_features = fitted_features
        self.fitted_target = fitted_target
        self.fitted_estimator = fitted_estimator



# Path: ramp/builders.py
# def build_featureset_safe(features, data, prep_index=None, train_index=None):
#     # check for dupes
#     colnames = set([f.unique_name for f in features])
#     assert len(features) == len(colnames), "Duplicate feature: %s" % colnames
#     if not features:
#         return
#     logging.info("Building %d features... " % len(features))
#     feature_datas = []
#     fitted_features = []
#     for feature in features:
#         d, ff = build_feature_safe(feature, data, prep_index, train_index)
#         feature_datas.append(d)
#         fitted_features.append(ff)
#     logging.info("Done building features")
#     return concat(feature_datas, axis=1), fitted_features
# 
# def build_target_safe(target, data, prep_index=None, train_index=None):
#     y, ff = target.build(data, prep_index, train_index)
#     return get_single_column(y), ff
# 
# def apply_featureset_safe(features, data, fitted_features):
#     assert len(features) == len(fitted_features), "%s, %s" % (len(features),
#                                                               len(fitted_features))
#     feature_datas = []
#     logging.info("Applying %d features to %d data points... " % (len(features), len(data)))
#     for f, ff in zip(features, fitted_features):
#         feature_datas.append(apply_feature_safe(f, data, ff))
#     logging.info("Done applying features")
#     return concat(feature_datas, axis=1)
# 
# def apply_target_safe(target, data, fitted_feature):
#     y = target.apply(data, fitted_feature)
#     return get_single_column(y)
# 
# def filter_data_and_indexes(model_def, data, prep_index=None, train_index=None):
#     for data_filter in model_def.filters:
#         data = data_filter(data)
#     if prep_index is not None:
#         prep_index = data.index & prep_index
#     if train_index is not None:
#         train_index = data.index & train_index
#     return data, prep_index, train_index
# 
# def filter_data(model_def, data):
#     return filter_data_and_indexes(model_def, data)[0]
# 
# Path: ramp/folds.py
# class BasicFolds(object):
# class WatertightFolds(BasicFolds):
# class BinaryTargetFolds(object):
# class BalancedFolds(BinaryTargetFolds):
# class BootstrapFolds(BalancedFolds):
# class BootstrapFoldsByPercentPositive(BootstrapFolds):
# class BootstrapFoldsBySize(BootstrapFolds):
#     def __init__(self, num_folds, data, repeat=1, seed=None):
#     def __iter__(self):
#     def __init__(self, num_folds, data, leakage_column, **kwargs):
#     def __iter__(self):
#     def __init__(self, target, data, seed=None):
#     def compute_folds(self):
#     def build_target(self):
#     def randomize(self):
#     def __iter__(self):
#     def __init__(self, num_folds, target, data, seed=None):
#     def compute_folds(self):
#     def __init__(self, num_folds, target, data,
#                   pos_train=None, pos_test=None, neg_train=None, neg_test=None,
#                   train_pos_percent=None, test_pos_percent=None, train_percent=None,
#                   seed=None):
#     def from_sizes(self):
#     def from_percents(self):
#     def compute_folds(self):
#     def __init__(self, num_folds, target, data,
#                  train_pos_percent, test_pos_percent, train_percent,
#                  seed=None):
#     def __init__(self, num_folds, target, data,
#                  pos_train=None, pos_test=None, neg_train=None, neg_test=None,
#                  seed=None):
# 
# Path: ramp/result.py
# class Result(Storable):
#     def __init__(self, x_train, x_test, y_train, y_test, y_preds, model_def, fitted_model, original_data):
#         """
#         Class for storing the result of a single model fit.
#         """
#         self.x_train = x_train
#         self.x_test = x_test
#         self.y_train = y_train
#         self.y_test = y_test
#         self.y_preds = y_preds
#         self.model_def = model_def
#         self.fitted_model = fitted_model
#         self.original_data = original_data
# 
# 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 key_from_index(idx):
#     return get_np_hash(idx.values)


# Path: ramp/modeling.py
import pandas as pd
from ramp.builders import (build_featureset_safe,
                           build_target_safe,
                           apply_featureset_safe,
                           apply_target_safe,
                           filter_data_and_indexes,
                           filter_data)
from ramp.folds import make_default_folds
from ramp.result import Result
from ramp.store import Storable
from ramp.utils import key_from_index




class FittedModel(Storable):

    def __init__(self,
                 model_def,
                 fitted_features,
                 fitted_target,
                 fitted_estimator):
        self.model_def = model_def
        self.fitted_features = fitted_features
        self.fitted_target = fitted_target
        self.fitted_estimator = fitted_estimator



class PackagedModel(Storable):