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

__all__ = ["Filter"]


from ....entrypoints.transforms_missingvaluesrowdropper import \
    transforms_missingvaluesrowdropper
from ....utils.utils import trace
from ...base_pipeline_item import BasePipelineItem, NoOutputSignature


class Filter(BasePipelineItem, NoOutputSignature):
    """

    Filters all rows where the input columns have value of NaN.

    .. remarks::
        ``Filter`` removes the entire row if any of the input columns have
        value of NaN in that row. This preprocessing is required for many ML
        algorithms that cannot work with NaNs. Useful if any NaN entry
        invalidates the entire row.

    :param complement: If true, keep only rows that contain NA values, and
        filter the rest.

    :param params: Additional arguments sent to compute engine.

    .. seealso::
        :py:class:`Indicator <nimbusml.preprocessing.missing_values.Indicator>`,
        :py:class:`Handler <nimbusml.preprocessing.missing_values.Handler>`.

    .. index:: filter, image

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

    @trace
    def __init__(
            self,
            complement=False,
            **params):
        BasePipelineItem.__init__(
            self, type='transform', **params)

        self.complement = complement

    @property
    def _entrypoint(self):
        return transforms_missingvaluesrowdropper

    @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))

        algo_args = dict(
            column=input_columns,
            complement=self.complement)

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