Ejemplo n.º 1
0
    def test_unordered_categorical_disallowed(self):
        """Test which verifies rt.nanmin raises an exception if called with an unordered Categorical."""
        # Create an unordered Categorical.
        cat = rt.Categorical(["PA", "NY", "NY", "AL", "LA", "PA", "CA", "IL", "IL", "FL", "FL", "LA"], ordered=False)
        assert not cat.ordered

        with pytest.raises(ValueError):
            rt.nanmin(cat)
Ejemplo n.º 2
0
    def test_nan_awareness(self, arr, func_type):
        """
        Check how :func:`rt.nanmin` handles NaN values by comparing it against :func:`rt.min`.

        Call :func:`rt.nanmin` with an array, then remove any NaNs from the array and call
        :func:`np.min` with the 'clean' array. The results should match.
        """
        # Get the function implementation based on how we want to call it.
        if func_type == 'module':
            test_func = lambda x: rt.nanmin(x)
        elif func_type == 'member':
            test_func = lambda x: x.nanmin()
        else:
            raise ValueError(
                f"Unhandled value '{func_type}' specified for the function type."
            )

        # Get the nan-unaware version of the function.
        nan_unaware_func = lambda x: rt.min(x)

        # Wrap the input as a FastArray to ensure we'll get the riptable implementation of the function.
        arr = rt.FA(arr)

        # Call the test implementation.
        NanAwareTestImpl.test_nan_awareness(test_func, nan_unaware_func, arr)
Ejemplo n.º 3
0
    def test_allnans(self, arg):
        # Call rt.nanmin with the test input.
        # It should raise a RuntimeWarning when given an input which
        # has all NaNs **on the specified axis**.
        with pytest.warns(RuntimeWarning):
            result = rt.nanmin(arg)

        # If given a scalar or 1D array (or some collection converted to such)
        # the result should be a NaN; for higher-rank arrays, the result should
        # be an array where one of the dimensions was collapsed and if there were
        # all NaNs along the selected axis there'll be a NaN there in the result.
        # TODO: Need to fix this to assert correctly for when rt.nanmin called with a higher-rank array.
        assert rt.isnan(result)
Ejemplo n.º 4
0
    def test_ordered_categorical_returns_scalar(self):
        """
        Test which verifies rt.nanmin returns a scalar (Python object or numpy scalar) representing the min Category given an ordered Categorical.
        """
        # Create an ordered Categorical (aka 'ordinal').
        cat = rt.Categorical(
            ["PA", "NY", "", "NY", "AL", "LA", "PA", "", "CA", "IL", "IL", "FL", "FL", "LA"], ordered=True)
        assert cat.ordered

        result = rt.nanmin(cat)

        # The result should either be a Python string, a numpy string scalar, or a Categorical scalar (if we implement one).
        is_py_str = isinstance(result, (bytes, str))
        is_np_scalar = isinstance(result, np.str)
        is_rt_cat = isinstance(result, rt.Categorical)
        assert is_py_str or is_np_scalar or is_rt_cat

        # Check the result is correct.
        assert result == "PA"
Ejemplo n.º 5
0
 def test_empty(self, arg):
     # Call rt.nanmin with an empty input -- it should raise a ValueError.
     with pytest.raises(ValueError):
         rt.nanmin(arg)