# Path: skutil/base.py
# def overrides(interface_class):
#     """Decorator for methods that override super methods. Provides
#     runtime validation that the method is, in fact, inherited from the
#     superclass. If not, will raise an ``AssertionError``.
# 
#     Parameters
#     ----------
# 
#     interface_class : type
#         The class/type from which the specified method is inherited.
#         If the method does not exist in the specified type, a ``RuntimeError``
#         will be raised.
# 
# 
#     Examples
#     --------
#     
#     The following is valid use:
# 
#         >>> class A(object):
#         ...     def a(self):
#         ...         return 1
# 
#         >>> class B(A):
#         ...     @overrides(A)
#         ...     def a(self):
#         ...         return 2
#         ...
#         ...     def b(self):
#         ...         return 0
# 
#     The following would be an invalid ``overrides`` statement, since
#     ``A`` does not have a ``b`` method to override.
# 
#         >>> class C(B): # doctest: +IGNORE_EXCEPTION_DETAIL
#         ...     @overrides(A) # should override B, not A
#         ...     def b(self):
#         ...         return 1
#         Traceback (most recent call last):  
#         AssertionError: A.b must override a super method!
# 
# 
#     .. versionadded:: 0.1.0
#     """
# 
#     def overrider(method):
#         assert (method.__name__ in dir(interface_class)), '%s.%s must override a super method!' % (
#             interface_class.__name__, method.__name__)
#         return method
# 
#     return overrider
# 
# Path: skutil/utils/fixes.py
# def _cols_if_none(X, self_cols):
#     """Since numerous transformers in the preprocessing
#     and feature selection modules take ``cols`` arguments
#     (which could end up as ``None`` via the ``validate_is_pd``
#     method), this will return the columns that should be used.
# 
#     Parameters
#     ----------
# 
#     X : Pandas ``DataFrame``
#         The data frame being transformed.
# 
#     self_cols : list (string) or None
#         The columns.
#     """
#     return X.columns.tolist() if not self_cols else self_cols
# 
# def _as_numpy(y):
#     """Given a 1d array or iterable, create
#     and return a np.ndarray of one-dimension.
# 
#     Parameters
#     ----------
# 
#     y : np.ndarray, shape(n_samples,)
#         The target being fit in the grid search.
# 
#     Returns
#     -------
# 
#     np.ndarray, shape(n_samples,)
#     """
#     if y is None:
#         return None
#     elif isinstance(y, np.ndarray):
#         return np.copy(y)
#     elif hasattr(y, 'as_matrix'):
#         return y.as_matrix()
#     elif hasattr(y, 'tolist'):
#         return y.tolist()
#     elif is_iterable(y):
#         return np.asarray([i for i in y])  # might accidentally force object type in 3
#     raise TypeError('cannot convert type %s to numpy ndarray' % type(y))


from abc import ABCMeta, abstractmethod
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.decomposition import PCA, TruncatedSVD
from sklearn.utils.validation import check_is_fitted
from sklearn.externals import six
from skutil.base import *
from skutil.base import overrides
from ..utils import *
from ..utils.fixes import _cols_if_none, _as_numpy
import numpy as np
import pandas as pd
        # fails thru if names don't exist:
        self.svd_ = TruncatedSVD(
            n_components=self.n_components,
            algorithm=self.algorithm,
            n_iter=self.n_iter).fit(X[cols].as_matrix())

        return self

    def transform(self, X):
        """Transform a test matrix given the already-fit transformer.

        Parameters
        ----------

        X : Pandas ``DataFrame``, shape=(n_samples, n_features)
            The Pandas frame to transform. The operation will
            be applied to a copy of the input data, and the result
            will be returned.


        Returns
        -------

        X : Pandas ``DataFrame``, shape=(n_samples, n_features)
            The operation is applied to a copy of ``X``,
            and the result set is returned.
        """
        check_is_fitted(self, 'svd_')
        # check on state of X and cols
        X, _ = validate_is_pd(X, self.cols)

# Path: skutil/base.py
# def overrides(interface_class):
#     """Decorator for methods that override super methods. Provides
#     runtime validation that the method is, in fact, inherited from the
#     superclass. If not, will raise an ``AssertionError``.
# 
#     Parameters
#     ----------
# 
#     interface_class : type
#         The class/type from which the specified method is inherited.
#         If the method does not exist in the specified type, a ``RuntimeError``
#         will be raised.
# 
# 
#     Examples
#     --------
#     
#     The following is valid use:
# 
#         >>> class A(object):
#         ...     def a(self):
#         ...         return 1
# 
#         >>> class B(A):
#         ...     @overrides(A)
#         ...     def a(self):
#         ...         return 2
#         ...
#         ...     def b(self):
#         ...         return 0
# 
#     The following would be an invalid ``overrides`` statement, since
#     ``A`` does not have a ``b`` method to override.
# 
#         >>> class C(B): # doctest: +IGNORE_EXCEPTION_DETAIL
#         ...     @overrides(A) # should override B, not A
#         ...     def b(self):
#         ...         return 1
#         Traceback (most recent call last):  
#         AssertionError: A.b must override a super method!
# 
# 
#     .. versionadded:: 0.1.0
#     """
# 
#     def overrider(method):
#         assert (method.__name__ in dir(interface_class)), '%s.%s must override a super method!' % (
#             interface_class.__name__, method.__name__)
#         return method
# 
#     return overrider
# 
# Path: skutil/utils/fixes.py
# def _cols_if_none(X, self_cols):
#     """Since numerous transformers in the preprocessing
#     and feature selection modules take ``cols`` arguments
#     (which could end up as ``None`` via the ``validate_is_pd``
#     method), this will return the columns that should be used.
# 
#     Parameters
#     ----------
# 
#     X : Pandas ``DataFrame``
#         The data frame being transformed.
# 
#     self_cols : list (string) or None
#         The columns.
#     """
#     return X.columns.tolist() if not self_cols else self_cols
# 
# def _as_numpy(y):
#     """Given a 1d array or iterable, create
#     and return a np.ndarray of one-dimension.
# 
#     Parameters
#     ----------
# 
#     y : np.ndarray, shape(n_samples,)
#         The target being fit in the grid search.
# 
#     Returns
#     -------
# 
#     np.ndarray, shape(n_samples,)
#     """
#     if y is None:
#         return None
#     elif isinstance(y, np.ndarray):
#         return np.copy(y)
#     elif hasattr(y, 'as_matrix'):
#         return y.as_matrix()
#     elif hasattr(y, 'tolist'):
#         return y.tolist()
#     elif is_iterable(y):
#         return np.asarray([i for i in y])  # might accidentally force object type in 3
#     raise TypeError('cannot convert type %s to numpy ndarray' % type(y))


# Path: skutil/decomposition/decompose.py
from abc import ABCMeta, abstractmethod
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.decomposition import PCA, TruncatedSVD
from sklearn.utils.validation import check_is_fitted
from sklearn.externals import six
from skutil.base import *
from skutil.base import overrides
from ..utils import *
from ..utils.fixes import _cols_if_none, _as_numpy
import numpy as np
import pandas as pd

        # fails thru if names don't exist:
        self.svd_ = TruncatedSVD(
            n_components=self.n_components,
            algorithm=self.algorithm,
            n_iter=self.n_iter).fit(X[cols].as_matrix())

        return self

    def transform(self, X):
        """Transform a test matrix given the already-fit transformer.

        Parameters
        ----------

        X : Pandas ``DataFrame``, shape=(n_samples, n_features)
            The Pandas frame to transform. The operation will
            be applied to a copy of the input data, and the result
            will be returned.


        Returns
        -------

        X : Pandas ``DataFrame``, shape=(n_samples, n_features)
            The operation is applied to a copy of ``X``,
            and the result set is returned.
        """
        check_is_fitted(self, 'svd_')
        # check on state of X and cols
        X, _ = validate_is_pd(X, self.cols)

        cols = _cols_if_none(X, self.cols)