Python more_itertools.first_true() Examples

The following are 17 code examples of more_itertools.first_true(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module more_itertools , or try the search function .
Example #1
Source File: parameters.py    From nyaggle with MIT License 6 votes vote down vote up
def get_hyperparam_byname(name: str, gbdt_type: str = 'lgbm', with_metadata: bool = False) -> Dict:
    """
    Get a hyperparameter by parameter name

    Args:
        name:
            The name of parameter (e.g. "ieee-2019-10th").
        gbdt_type:
            The type of gbdt library. ``lgbm``, ``cat``, ``xgb`` can be used.
        with_metadata:
            When set to True, parameters are wrapped by metadata dictionary which contains information about
            source URL, competition name etc.
    Returns:
        A hyperparameter dictionary.
    """
    param_table = _get_table(gbdt_type)
    found = first_true(param_table, pred=lambda x: x['name'] == name)
    if found is None:
        raise RuntimeError('Hyperparameter {} not found.'.format(name))

    return _return(found, with_metadata) 
Example #2
Source File: test_recipes.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def test_pred(self):
        """Test with a custom predicate"""
        self.assertEqual(
            mi.first_true([2, 4, 6], pred=lambda x: x % 3 == 0), 6
        ) 
Example #3
Source File: test_recipes.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_something_true(self):
        """Test with no keywords"""
        self.assertEqual(mi.first_true(range(10)), 1) 
Example #4
Source File: test_recipes.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def test_default(self):
        """Test with a default keyword"""
        self.assertEqual(mi.first_true([0, 0, 0], default='!'), '!') 
Example #5
Source File: test_recipes.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def test_nothing_true(self):
        """Test default return value."""
        self.assertIsNone(mi.first_true([0, 0, 0])) 
Example #6
Source File: test_recipes.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def test_something_true(self):
        """Test with no keywords"""
        self.assertEqual(mi.first_true(range(10)), 1) 
Example #7
Source File: test_recipes.py    From pipenv with MIT License 5 votes vote down vote up
def test_pred(self):
        """Test with a custom predicate"""
        self.assertEqual(
            mi.first_true([2, 4, 6], pred=lambda x: x % 3 == 0), 6
        ) 
Example #8
Source File: test_recipes.py    From pipenv with MIT License 5 votes vote down vote up
def test_default(self):
        """Test with a default keyword"""
        self.assertEqual(mi.first_true([0, 0, 0], default='!'), '!') 
Example #9
Source File: test_recipes.py    From pipenv with MIT License 5 votes vote down vote up
def test_nothing_true(self):
        """Test default return value."""
        self.assertIsNone(mi.first_true([0, 0, 0])) 
Example #10
Source File: test_recipes.py    From pipenv with MIT License 5 votes vote down vote up
def test_something_true(self):
        """Test with no keywords"""
        self.assertEqual(mi.first_true(range(10)), 1) 
Example #11
Source File: parameters.py    From nyaggle with MIT License 5 votes vote down vote up
def _get_hyperparam_byname(param_table: List[Dict], name: str, with_metadata: bool):
    found = first_true(param_table, pred=lambda x: x['name'] == name)
    if found is None:
        raise RuntimeError('Hyperparameter {} not found.'.format(name))

    if with_metadata:
        return found
    else:
        return found['parameters'] 
Example #12
Source File: test_recipes.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_pred(self):
        """Test with a custom predicate"""
        self.assertEqual(
            mi.first_true([2, 4, 6], pred=lambda x: x % 3 == 0), 6
        ) 
Example #13
Source File: test_recipes.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_default(self):
        """Test with a default keyword"""
        self.assertEqual(mi.first_true([0, 0, 0], default='!'), '!') 
Example #14
Source File: test_recipes.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_something_true(self):
        """Test with no keywords"""
        self.assertEqual(mi.first_true(range(10)), 1) 
Example #15
Source File: test_recipes.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_pred(self):
        """Test with a custom predicate"""
        self.assertEqual(
            mi.first_true([2, 4, 6], pred=lambda x: x % 3 == 0), 6
        ) 
Example #16
Source File: test_recipes.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_default(self):
        """Test with a default keyword"""
        self.assertEqual(mi.first_true([0, 0, 0], default='!'), '!') 
Example #17
Source File: test_recipes.py    From python-netsurv with MIT License 5 votes vote down vote up
def test_nothing_true(self):
        """Test default return value."""
        self.assertIsNone(mi.first_true([0, 0, 0]))