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

__all__ = ["RangeFilter"]


from ....entrypoints.transforms_rowrangefilter import transforms_rowrangefilter
from ....utils.utils import trace
from ...base_pipeline_item import (BasePipelineItem,
                                   SingleInputAsStringSignature)


class RangeFilter(BasePipelineItem, SingleInputAsStringSignature):
    """

    Filters a dataview on a column of type Single, Double or Key
    (contiguous).
    Keeps the values that are in the specified min/max range.
    NaNs are always filtered out.
    If the input is a Key type, the min/max are considered percentages of
    the number of values.

    :param min: Minimum value (0 to 1 for key types).

    :param max: Maximum value (0 to 1 for key types).

    :param complement: If true, keep the values that fall outside the range.

    :param include_min: If true, include in the range the values that are
        equal to min.

    :param include_max: If true, include in the range the values that are
        equal to max.

    :param params: Additional arguments sent to compute engine.

    .. index:: transform, random

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

    @trace
    def __init__(
            self,
            min=-1,
            max=None,
            complement=False,
            include_min=True,
            include_max=None,
            **params):
        BasePipelineItem.__init__(
            self, type='transform', **params)

        self.min = min
        self.max = max
        self.complement = complement
        self.include_min = include_min
        self.include_max = include_max

    @property
    def _entrypoint(self):
        return transforms_rowrangefilter

    @trace
    def _get_node(self, **all_args):

        input_column = self.input
        if input_column is None and 'input' in all_args:
            input_column = all_args['input']
        if 'input' in all_args:
            all_args.pop('input')

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

        if not isinstance(input_column, str):
            raise ValueError(
                "input has to be a string, instead got %s" %
                type(input_column))

        algo_args = dict(
            column=input_column,
            min=self.min,
            max=self.max,
            complement=self.complement,
            include_min=self.include_min,
            include_max=self.include_max)

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