Ejemplo n.º 1
0
def test_pred_non_int_count_fix():
    testrows = [
        {'ColInt':3, 'ColFloat':None, 'ColCat': 'a', 'ColBool':True},
        {'ColInt': '4', 'ColFloat':None, 'ColCat': 'b', 'ColBool':False}]
    clean_predictions(testrows, vschema)
    assert testrows[1]['ColInt'] == 4
    validate_predictions(testrows, vschema)
Ejemplo n.º 2
0
def test_pred_nonvalid_float_real_fix():
    testrows = [
        {'ColInt':None, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'ColInt':None, 'ColFloat': 'jello', 'ColCat': 'b', 'ColBool':False}]
    clean_predictions(testrows, vschema)
    assert not('ColFloat' in testrows[1])
    validate_predictions(testrows, vschema)
Ejemplo n.º 3
0
def test_pred_non_float_real_fix():
    testrows = [
        {'ColInt':None, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'ColInt':None, 'ColFloat': '4.1', 'ColCat': 'b', 'ColBool':False}]
    clean_predictions(testrows, vschema)
    assert testrows[1]['ColFloat'] == 4.1
    validate_predictions(testrows, vschema)
Ejemplo n.º 4
0
def test_pred_int_count_limit_fix():
    testrows = [
        {'_request_id': '0', 'ColInt':3, 'ColFloat':None, 'ColCat': 'a',
         'ColBool':True},
        {'_request_id': '1', 'ColInt': 100001, 'ColFloat':None, 'ColCat': 'b',
         'ColBool':False}]
    clean_predictions(testrows, vschema)
    assert 'ColInt' not in testrows[1]
    validate_predictions(testrows, vschema)
Ejemplo n.º 5
0
def test_pred_extrafield_fix():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':None, 'ColCat': 'a', 'ColBool':True},
        {'ColEx':None, 'ColInt':4, 'ColFloat':None, 'ColCat': 'b',
         'ColBool':False}]
    clean_predictions(testrows, vschema)
    assert not('_id' in testrows[0])
    assert not('ColEx' in testrows[1])
    validate_predictions(testrows, vschema)
Ejemplo n.º 6
0
def test_pred_non_bool_boolean_truefix():
    testrows = [{
        'ColInt': None,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': '1'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': '2'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'True'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'true'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'Yes'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'YES'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'Y'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'y'
    }]
    clean_predictions(testrows, vschema)
    for r in testrows:
        assert r['ColBool'] == True
    validate_predictions(testrows, vschema)
Ejemplo n.º 7
0
def test_pred_nonvalid_bool_boolean_fix():
    testrows = [{
        'ColInt': None,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'jello'
    }]
    clean_predictions(testrows, vschema)
    assert not ('ColBool' in testrows[1])
    validate_predictions(testrows, vschema)
Ejemplo n.º 8
0
def test_pred_non_int_count_fix():
    testrows = [{
        'ColInt': 3,
        'ColFloat': None,
        'ColCat': 'a',
        'ColBool': True
    }, {
        'ColInt': '4',
        'ColFloat': None,
        'ColCat': 'b',
        'ColBool': False
    }]
    clean_predictions(testrows, vschema)
    assert testrows[1]['ColInt'] == 4
    validate_predictions(testrows, vschema)
Ejemplo n.º 9
0
def test_pred_non_str_cat_fix():
    testrows = [{
        'ColInt': None,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 3,
        'ColBool': False
    }]
    clean_predictions(testrows, vschema)
    assert testrows[1]['ColCat'] == '3'
    validate_predictions(testrows, vschema)
Ejemplo n.º 10
0
def test_pred_non_float_real_fix():
    testrows = [{
        'ColInt': None,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        'ColInt': None,
        'ColFloat': '4.1',
        'ColCat': 'b',
        'ColBool': False
    }]
    clean_predictions(testrows, vschema)
    assert testrows[1]['ColFloat'] == 4.1
    validate_predictions(testrows, vschema)
Ejemplo n.º 11
0
def test_pred_nonvalid_int_count_fix():
    testrows = [{
        'ColInt': 3,
        'ColFloat': None,
        'ColCat': 'a',
        'ColBool': True
    }, {
        'ColInt': 'jello',
        'ColFloat': None,
        'ColCat': 'b',
        'ColBool': False
    }]
    clean_predictions(testrows, vschema)
    assert not ('ColInt' in testrows[1])
    validate_predictions(testrows, vschema)
Ejemplo n.º 12
0
def test_pred_too_many_cats_fail():
    eschema = {'ColCat': {'type': 'categorical'}}
    testrows = []
    rid = 0
    maxCols = 256
    for i in range(maxCols - 1):
        testrows.append({'_request_id': str(rid), 'ColCat': str(i)})
        rid += 1
        testrows.append({'_request_id': str(rid), 'ColCat': str(i)})
        rid += 1
    testrows.append({'_request_id': str(rid), 'ColCat': str(maxCols - 1)})
    testrows.append({'_request_id': str(rid + 1), 'ColCat': str(maxCols)})
    assert_raises(VeritableError, validate_predictions, testrows, eschema)
    try:
        validate_predictions(testrows, eschema)
    except VeritableError as e:
        assert e.col == 'ColCat'
Ejemplo n.º 13
0
def test_pred_int_count_limit_fix():
    testrows = [{
        '_request_id': '0',
        'ColInt': 3,
        'ColFloat': None,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_request_id': '1',
        'ColInt': 100001,
        'ColFloat': None,
        'ColCat': 'b',
        'ColBool': False
    }]
    clean_predictions(testrows, vschema)
    assert 'ColInt' not in testrows[1]
    validate_predictions(testrows, vschema)
Ejemplo n.º 14
0
def test_pred_non_bool_boolean_falsefix():
    testrows = [{
        'ColInt': None,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': False
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': '0'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'False'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'false'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'No'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'NO'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'N'
    }, {
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'n'
    }]
    clean_predictions(testrows, vschema)
    for r in testrows:
        assert r['ColBool'] == False
    validate_predictions(testrows, vschema)
Ejemplo n.º 15
0
def test_pred_extrafield_fix():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': None,
        'ColCat': 'a',
        'ColBool': True
    }, {
        'ColEx': None,
        'ColInt': 4,
        'ColFloat': None,
        'ColCat': 'b',
        'ColBool': False
    }]
    clean_predictions(testrows, vschema)
    assert not ('_id' in testrows[0])
    assert not ('ColEx' in testrows[1])
    validate_predictions(testrows, vschema)
Ejemplo n.º 16
0
def test_pred_int_count_limit_fail():
    testrows = [{
        '_request_id': '0',
        'ColInt': 3,
        'ColFloat': None,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_request_id': '1',
        'ColInt': 100001,
        'ColFloat': None,
        'ColCat': 'b',
        'ColBool': False
    }]
    assert_raises(VeritableError, validate_predictions, testrows, vschema)
    try:
        validate_predictions(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
        assert e.col == 'ColInt'
Ejemplo n.º 17
0
def test_pred_nonvalid_bool_boolean_fail():
    testrows = [{
        '_request_id': '0',
        'ColInt': None,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_request_id': '1',
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'jello'
    }]
    assert_raises(VeritableError, validate_predictions, testrows, vschema)
    try:
        validate_predictions(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
        assert e.col == 'ColBool'
Ejemplo n.º 18
0
def test_pred_valid_rows_id():
    refrows = [{
        '_request_id': '0',
        'ColInt': None,
        'ColFloat': None,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_request_id': '1',
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': None,
        'ColBool': False
    }, {
        '_request_id': '2',
        'ColInt': None,
        'ColFloat': None
    }]
    testrows = [{
        '_request_id': '0',
        'ColInt': None,
        'ColFloat': None,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_request_id': '1',
        'ColInt': None,
        'ColFloat': 4.1,
        'ColCat': None,
        'ColBool': False
    }, {
        '_request_id': '2',
        'ColInt': None,
        'ColFloat': None
    }]
    validate_predictions(testrows, vschema)
    assert testrows == refrows
    clean_predictions(testrows, vschema)
    assert testrows == refrows