Example #1
0
def test_pandas_GenderBender_sp_prefix( ):
    import numpy as np;
    import pandas as pd;
    constructor = filters.Pandas_Fix( )

    start = pd.DataFrame( { 'id': [ 1, 2, 3, 4], 'sex': [ 'male', 'female', None, 'male']
        } )

    #
    # Remember that the default result will have columns sorted by column name in
    # alphabetical order.
    #
    expected = pd.DataFrame( { 'sp_female': [ 0, 1, 0, 0], 'sp_male': [ 1, 0, 0, 1], 
                                   'sp_unspecified':[ 0, 0, 1, 0]
        } )

    #
    # Right now the underlyimg pandas code in the utility that we're testing
    # 'helpfully' compresses everything to int8 so we have to match that.
    #
    expected = expected.astype( np.uint8 )
    
    answer = constructor.decode_cell( 'ptest_table', 'sp_genderName',  start['sex'] )

    from pandas.util.testing import assert_frame_equal

    assert_frame_equal( answer.sort_index( axis=1),
                            expected.sort_index( axis=1),
                            check_names=True )
Example #2
0
def test_pandas_GenderBender_BadArg( ):
    import numpy as np;
    import pandas as pd;
    constructor = filters.Pandas_Fix( )

    with pytest.raises( TypeError ):
        answer = constructor.decode_cell( 'ptest_table', 'genderName',  ['mail', 'other'] )    
Example #3
0
def test_pandas_datetime_badDate_3( ):
    import datetime

    constructor = filters.Pandas_Fix( )

    answer = constructor.decode_cell( 'ptest_table', 'datetimeName', None )

    assert answer == None
Example #4
0
def test_pandas_datetime_badDate_1( ):
    import datetime

    constructor = filters.Pandas_Fix( )

    myDateObject = datetime.datetime( 2009, 1, 1, 2, 2, 2)
    answer = constructor.decode_cell( 'ptest_table', 'datetimeName', myDateObject )

    assert answer == None
Example #5
0
def test_pandas_boolean_BadType( ):
    constructor = filters.Pandas_Fix( )

    with pytest.raises( ValueError ):
        answer = constructor.decode_cell( 'ptest_table', 'booleanName',  'Fred' )
Example #6
0
def test_pandas_boolean_GoodValue_6(  ):
    constructor = filters.Pandas_Fix( )
    answer = constructor.decode_cell( 'ptest_table', 'booleanName',  -5 )

    assert answer == 1
Example #7
0
def test_pandas_ZTest_BadType( ):
    constructor = filters.Pandas_Fix( )

    with pytest.raises( ValueError ):
        answer = constructor.decode_cell( 'ptest_table', 'naturalNumbersName',  'Fred' )
Example #8
0
def test_pandas_ZTest_GoodNumber_5( ):
    constructor = filters.Pandas_Fix( )

    answer = constructor.decode_cell( 'ptest_table', 'naturalNumbersName',  -5 )

    assert answer == 0