# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------------------------
# - Generated by tools/entrypoint_compiler.py: do not edit by hand
"""
ColumnSelector
"""

__all__ = ["ColumnSelector"]


from ....entrypoints.transforms_columnselector import transforms_columnselector
from ....utils.utils import trace
from ...base_pipeline_item import BasePipelineItem, NoOutputSignature


class ColumnSelector(BasePipelineItem, NoOutputSignature):
    """

    Selects a set of columns to retrain, dropping all others.

    :param keep_columns: List of columns to keep.

    :param drop_columns: List of columns to drop.

    :param keep_hidden: Specifies whether to keep or remove hidden columns.

    :param ignore_missing: Specifies whether to ignore columns that are missing
        from the input.

    :param params: Additional arguments sent to compute engine.

    .. seealso::
        :py:class:`ColumnConcatenator
        <nimbusml.preprocessing.schema.ColumnConcatenator>`,
        :py:class:`ColumnDropper
        <nimbusml.preprocessing.schema.ColumnDropper>`.

    .. index:: transform, schema

    Example:
       .. literalinclude:: /../nimbusml/examples/ColumnSelector.py
              :language: python
    """

    @trace
    def __init__(
            self,
            keep_columns=None,
            drop_columns=None,
            keep_hidden=False,
            ignore_missing=False,
            **params):
        BasePipelineItem.__init__(
            self, type='transform', **params)

        self.keep_columns = keep_columns
        self.drop_columns = drop_columns
        self.keep_hidden = keep_hidden
        self.ignore_missing = ignore_missing

    @property
    def _entrypoint(self):
        return transforms_columnselector

    @trace
    def _get_node(self, **all_args):
        input_columns = self.input
        if input_columns is None and 'input' in all_args:
            input_columns = all_args['input']
        if 'input' in all_args:
            all_args.pop('input')

        # validate input
        if input_columns is None:
            raise ValueError(
                "'None' input passed when it cannot be none.")

        if not isinstance(input_columns, list):
            raise ValueError(
                "input has to be a list of strings, instead got %s" %
                type(input_columns))

        keep_columns = self.keep_columns
        if self.keep_columns is None and self.drop_columns is None:
            keep_columns = input_columns
        algo_args = dict(
            column=input_columns,
            keep_columns=keep_columns,
            drop_columns=self.drop_columns,
            keep_hidden=self.keep_hidden,
            ignore_missing=self.ignore_missing)

        all_args.update(algo_args)
        return self._entrypoint(**all_args)
