# Path: ramp/features/base.py
# class BaseFeature(object):
#     """
#     BaseFeature wraps a string corresponding to a
#     DataFrame column.
#     """
# 
#     _cacheable = True
# 
#     def __init__(self, feature):
#         if not isinstance(feature, basestring):
#             raise ValueError('Base feature must be a string')
#         self.feature = feature
# 
#     def __repr__(self):
#         return repr(self.feature)
# 
#     def __str__(self):
#         return str(self.feature)
# 
#     @property
#     def unique_name(self):
#         return str(self)
# 
#     def depends_on_y(self):
#         return False
# 
#     def depends_on_other_x(self):
#         return False
# 
#     @property
#     def is_trained(self):
#         return self.depends_on_y()
# 
#     @property
#     def is_prepped(self):
#         return self.depends_on_other_x()
# 
#     def __call__(self, *args, **kwargs):
#         return self.apply(*args, **kwargs)
# 
#     def build(self, data, prep_index=None, train_index=None):
#         feature_data = self.apply(data)
#         return feature_data, None
# 
#     def apply(self, data, fitted_feature=None):
#         return DataFrame(data[self.feature],
#                          columns=[self.feature])
# 
#     def prepare(self, prep_data):
#         raise NotImplementedError
# 
#     def train(self, train_data):
#         raise NotImplementedError
# 
#     def __add__(self, other):
#         return combo.Add([self, other])
# 
#     def __sub__(self, other):
#         return combo.Sub([self, other])
# 
#     def __div__(self, other):
#         return combo.Divide([self, other])
# 
#     def __mul__(self, other):
#         return combo.Multiply([self, other])
# 
#     def __pow__(self, power):
#         return Power(self, power)
# 
# class Feature(ComboFeature):
#     """
#     Base class for features operating on a single feature.
#     """
#     def __init__(self, feature):
#         super(Feature, self).__init__([feature])
#         self.feature = self.features[0]
# 
#     # def apply(self, data, fitted_feature):
#     #     # recurse:
#     #     data = self.feature.apply(data, fitted_feature.inner_fitted_feature)
#     #     # apply this feature's transformation:
#     #     feature_data = self._apply(data, fitted_feature)
#     #     if not isinstance(feature_data, DataFrame):
#     #         raise TypeError("_apply() method must return a DataFrame")
#     #     return self._prepend_feature_name_to_all_columns(feature_data)
# 
#     def _apply(self, data, fitted_feature):
#         return data
# 
#     def _combine_apply(self, datas, fitted_feature):
#         return self._apply(datas[0], fitted_feature)
# 
#     def prepare(self, prep_datas):
#         if hasattr(self, '_prepare'):
#             prepped_data = self._prepare(prep_datas[0])
#             return prepped_data
#         else:
#             return None
# 
#     def train(self, train_datas):
#         if hasattr(self, '_train'):
#             trained_data = self._train(train_datas[0])
#             return trained_data
#         else:
#             return None
# 
# class ConstantFeature(BaseFeature):
# 
#     def __init__(self, feature):
#         if not isinstance(feature, int) and not isinstance(feature, float):
#             raise ValueError('Constant feature must be a number')
#         self.feature = feature
# 
#     def apply(self, data, fitted_feature=None):
#         return DataFrame(np.repeat(self.feature, len(data)),
#                          index=data.index,
#                          columns=['%s' % self.feature])
# 
# 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_single_column(df):
#     if len(df.columns) != 1:
#         raise ValueError("More than one column")
#     return df[df.columns[0]]


import logging
import numpy as np
from pandas import concat, DataFrame, Series, Index
from ramp.features.base import BaseFeature, Feature, ConstantFeature
from ramp.utils import _pprint, get_single_column




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_target_safe(target, data, fitted_feature):
    y = target.apply(data, fitted_feature)

# Path: ramp/features/base.py
# class BaseFeature(object):
#     """
#     BaseFeature wraps a string corresponding to a
#     DataFrame column.
#     """
# 
#     _cacheable = True
# 
#     def __init__(self, feature):
#         if not isinstance(feature, basestring):
#             raise ValueError('Base feature must be a string')
#         self.feature = feature
# 
#     def __repr__(self):
#         return repr(self.feature)
# 
#     def __str__(self):
#         return str(self.feature)
# 
#     @property
#     def unique_name(self):
#         return str(self)
# 
#     def depends_on_y(self):
#         return False
# 
#     def depends_on_other_x(self):
#         return False
# 
#     @property
#     def is_trained(self):
#         return self.depends_on_y()
# 
#     @property
#     def is_prepped(self):
#         return self.depends_on_other_x()
# 
#     def __call__(self, *args, **kwargs):
#         return self.apply(*args, **kwargs)
# 
#     def build(self, data, prep_index=None, train_index=None):
#         feature_data = self.apply(data)
#         return feature_data, None
# 
#     def apply(self, data, fitted_feature=None):
#         return DataFrame(data[self.feature],
#                          columns=[self.feature])
# 
#     def prepare(self, prep_data):
#         raise NotImplementedError
# 
#     def train(self, train_data):
#         raise NotImplementedError
# 
#     def __add__(self, other):
#         return combo.Add([self, other])
# 
#     def __sub__(self, other):
#         return combo.Sub([self, other])
# 
#     def __div__(self, other):
#         return combo.Divide([self, other])
# 
#     def __mul__(self, other):
#         return combo.Multiply([self, other])
# 
#     def __pow__(self, power):
#         return Power(self, power)
# 
# class Feature(ComboFeature):
#     """
#     Base class for features operating on a single feature.
#     """
#     def __init__(self, feature):
#         super(Feature, self).__init__([feature])
#         self.feature = self.features[0]
# 
#     # def apply(self, data, fitted_feature):
#     #     # recurse:
#     #     data = self.feature.apply(data, fitted_feature.inner_fitted_feature)
#     #     # apply this feature's transformation:
#     #     feature_data = self._apply(data, fitted_feature)
#     #     if not isinstance(feature_data, DataFrame):
#     #         raise TypeError("_apply() method must return a DataFrame")
#     #     return self._prepend_feature_name_to_all_columns(feature_data)
# 
#     def _apply(self, data, fitted_feature):
#         return data
# 
#     def _combine_apply(self, datas, fitted_feature):
#         return self._apply(datas[0], fitted_feature)
# 
#     def prepare(self, prep_datas):
#         if hasattr(self, '_prepare'):
#             prepped_data = self._prepare(prep_datas[0])
#             return prepped_data
#         else:
#             return None
# 
#     def train(self, train_datas):
#         if hasattr(self, '_train'):
#             trained_data = self._train(train_datas[0])
#             return trained_data
#         else:
#             return None
# 
# class ConstantFeature(BaseFeature):
# 
#     def __init__(self, feature):
#         if not isinstance(feature, int) and not isinstance(feature, float):
#             raise ValueError('Constant feature must be a number')
#         self.feature = feature
# 
#     def apply(self, data, fitted_feature=None):
#         return DataFrame(np.repeat(self.feature, len(data)),
#                          index=data.index,
#                          columns=['%s' % self.feature])
# 
# 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_single_column(df):
#     if len(df.columns) != 1:
#         raise ValueError("More than one column")
#     return df[df.columns[0]]


# Path: ramp/builders.py
import logging
import numpy as np
from pandas import concat, DataFrame, Series, Index
from ramp.features.base import BaseFeature, Feature, ConstantFeature
from ramp.utils import _pprint, get_single_column





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_target_safe(target, data, fitted_feature):
    y = target.apply(data, fitted_feature)

    return get_single_column(y)