Exemple #1
0
def validate_bool_kwarg(value, arg_name):
    """ Ensures that argument passed in arg_name is of type bool. """
    if not (is_bool(value) or value is None):
        raise ValueError('For argument "%s" expected type bool, '
                         'received type %s.' %
                         (arg_name, type(value).__name__))
    return value
Exemple #2
0
def validate_bool_kwarg(value, arg_name):
    """ Ensures that argument passed in arg_name is of type bool. """
    if not (is_bool(value) or value is None):
        raise ValueError('For argument "%s" expected type bool, '
                         'received type %s.' %
                         (arg_name, type(value).__name__))
    return value
Exemple #3
0
def validate_cum_func_with_skipna(skipna, args, kwargs, name):
    """
    If this function is called via the 'numpy' library, the third
    parameter in its signature is 'dtype', which takes either a
    'numpy' dtype or 'None', so check if the 'skipna' parameter is
    a boolean or not
    """
    if not is_bool(skipna):
        args = (skipna,) + args
        skipna = True

    validate_cum_func(args, kwargs, fname=name)
    return skipna
def _check_for_default_values(fname, arg_val_dict, compat_args):
    """
    Check that the keys in `arg_val_dict` are mapped to their
    default values as specified in `compat_args`.

    Note that this function is to be called only when it has been
    checked that arg_val_dict.keys() is a subset of compat_args

    """
    for key in arg_val_dict:
        # try checking equality directly with '=' operator,
        # as comparison may have been overriden for the left
        # hand object
        try:
            v1 = arg_val_dict[key]
            v2 = compat_args[key]

            # check for None-ness otherwise we could end up
            # comparing a numpy array vs None
            if (v1 is not None and v2 is None) or (v1 is None and v2 is not None):
                match = False
            else:
                match = v1 == v2

            if not is_bool(match):
                raise ValueError("'match' is not a boolean")

        # could not compare them directly, so try comparison
        # using the 'is' operator
        except:
            match = arg_val_dict[key] is compat_args[key]

        if not match:
            raise ValueError(
                (
                    "the '{arg}' parameter is not "
                    "supported in the pandas "
                    "implementation of {fname}()".format(fname=fname, arg=key)
                )
            )
Exemple #5
0
def _check_for_default_values(fname, arg_val_dict, compat_args):
    """
    Check that the keys in `arg_val_dict` are mapped to their
    default values as specified in `compat_args`.

    Note that this function is to be called only when it has been
    checked that arg_val_dict.keys() is a subset of compat_args

    """
    for key in arg_val_dict:
        # try checking equality directly with '=' operator,
        # as comparison may have been overriden for the left
        # hand object
        try:
            v1 = arg_val_dict[key]
            v2 = compat_args[key]

            # check for None-ness otherwise we could end up
            # comparing a numpy array vs None
            if (v1 is not None and v2 is None) or \
               (v1 is None and v2 is not None):
                match = False
            else:
                match = (v1 == v2)

            if not is_bool(match):
                raise ValueError("'match' is not a boolean")

        # could not compare them directly, so try comparison
        # using the 'is' operator
        except:
            match = (arg_val_dict[key] is compat_args[key])

        if not match:
            raise ValueError(("the '{arg}' parameter is not "
                              "supported in the pandas "
                              "implementation of {fname}()".
                              format(fname=fname, arg=key)))
Exemple #6
0
    def test_is_bool(self):
        self.assertTrue(is_bool(True))
        self.assertTrue(is_bool(np.bool(False)))
        self.assertTrue(is_bool(np.bool_(False)))

        self.assertFalse(is_bool(1))
        self.assertFalse(is_bool(1.1))
        self.assertFalse(is_bool(1 + 3j))
        self.assertFalse(is_bool(np.int64(1)))
        self.assertFalse(is_bool(np.float64(1.1)))
        self.assertFalse(is_bool(np.complex128(1 + 3j)))
        self.assertFalse(is_bool(np.nan))
        self.assertFalse(is_bool(None))
        self.assertFalse(is_bool('x'))
        self.assertFalse(is_bool(datetime(2011, 1, 1)))
        self.assertFalse(is_bool(np.datetime64('2011-01-01')))
        self.assertFalse(is_bool(Timestamp('2011-01-01')))
        self.assertFalse(is_bool(Timestamp('2011-01-01',
                                           tz='US/Eastern')))
        self.assertFalse(is_bool(timedelta(1000)))
        self.assertFalse(is_bool(np.timedelta64(1, 'D')))
        self.assertFalse(is_bool(Timedelta('1 days')))
Exemple #7
0
    def test_is_bool(self):
        self.assertTrue(is_bool(True))
        self.assertTrue(is_bool(np.bool(False)))
        self.assertTrue(is_bool(np.bool_(False)))

        self.assertFalse(is_bool(1))
        self.assertFalse(is_bool(1.1))
        self.assertFalse(is_bool(1 + 3j))
        self.assertFalse(is_bool(np.int64(1)))
        self.assertFalse(is_bool(np.float64(1.1)))
        self.assertFalse(is_bool(np.complex128(1 + 3j)))
        self.assertFalse(is_bool(np.nan))
        self.assertFalse(is_bool(None))
        self.assertFalse(is_bool('x'))
        self.assertFalse(is_bool(datetime(2011, 1, 1)))
        self.assertFalse(is_bool(np.datetime64('2011-01-01')))
        self.assertFalse(is_bool(Timestamp('2011-01-01')))
        self.assertFalse(is_bool(Timestamp('2011-01-01', tz='US/Eastern')))
        self.assertFalse(is_bool(timedelta(1000)))
        self.assertFalse(is_bool(np.timedelta64(1, 'D')))
        self.assertFalse(is_bool(Timedelta('1 days')))