Best Python code snippet using pandera_python
vectorization_test.py
Source:vectorization_test.py  
...104    mg = sparse_meshgrid(np.arange(5) - 3)105    val_1 = -1106    val_2 = 2107    @vectorize(otypes=['int'])108    def simple_func(x):109        return 0 if x < 0 else 1110    true_result_arr = [0, 0, 1, 1, 1]111    true_result_mg = [0, 0, 0, 1, 1]112    # Out-of-place113    out = simple_func(arr)114    assert isinstance(out, np.ndarray)115    assert out.dtype == np.dtype('int')116    assert out.shape == (5,)117    assert all_equal(out, true_result_arr)118    out = simple_func(mg)119    assert isinstance(out, np.ndarray)120    assert out.shape == (5,)121    assert out.dtype == np.dtype('int')122    assert all_equal(out, true_result_mg)123    assert simple_func(val_1) == 0124    assert simple_func(val_2) == 1125    # Python 2 really swallows this stuff in comparisons...126    bogus_input = [lambda x: x, object, Exception]127    if sys.version_info.major > 2:128        for b in bogus_input:129            with pytest.raises(TypeError):130                simple_func(b)131    # In-place132    out = np.empty(5, dtype='int')133    simple_func(arr, out=out)134    assert all_equal(out, true_result_arr)135    out = np.empty(5, dtype='int')136    simple_func(mg, out=out)137    assert all_equal(out, true_result_mg)138def test_vectorize_1d_lazy():139    # Test vectorization in 1d without data type --> lazy vectorization140    arr = (np.arange(5) - 2)[None, :]141    mg = sparse_meshgrid(np.arange(5) - 3)142    val_1 = -1143    val_2 = 2144    @vectorize145    def simple_func(x):146        return 0 if x < 0 else 1147    true_result_arr = [0, 0, 1, 1, 1]148    true_result_mg = [0, 0, 0, 1, 1]149    # Out-of-place150    out = simple_func(arr)151    assert isinstance(out, np.ndarray)152    assert is_int_dtype(out.dtype)153    assert out.shape == (5,)154    assert all_equal(out, true_result_arr)155    out = simple_func(mg)156    assert isinstance(out, np.ndarray)157    assert out.shape == (5,)158    assert is_int_dtype(out.dtype)159    assert all_equal(out, true_result_mg)160    assert simple_func(val_1) == 0161    assert simple_func(val_2) == 1162def test_vectorize_2d_dtype():163    # Test vectorization in 2d with given data type for output164    arr = np.empty((2, 5), dtype='int')165    arr[0] = ([-3, -2, -1, 0, 1])166    arr[1] = ([-1, 0, 1, 2, 3])167    mg = sparse_meshgrid([-3, -2, -1, 0, 1], [-1, 0, 1, 2, 3])168    val_1 = (-1, 1)169    val_2 = (2, 1)170    @vectorize(otypes=['int'])171    def simple_func(x):172        return 0 if x[0] < 0 and x[1] > 0 else 1173    true_result_arr = [1, 1, 0, 1, 1]174    true_result_mg = [[1, 1, 0, 0, 0],175                      [1, 1, 0, 0, 0],176                      [1, 1, 0, 0, 0],177                      [1, 1, 1, 1, 1],178                      [1, 1, 1, 1, 1]]179    # Out-of-place180    out = simple_func(arr)181    assert isinstance(out, np.ndarray)182    assert out.dtype == np.dtype('int')183    assert out.shape == (5,)184    assert all_equal(out, true_result_arr)185    out = simple_func(mg)186    assert isinstance(out, np.ndarray)187    assert out.dtype == np.dtype('int')188    assert out.shape == (5, 5)189    assert all_equal(out, true_result_mg)190    assert simple_func(val_1) == 0191    assert simple_func(val_2) == 1192    # In-place193    out = np.empty(5, dtype='int')194    simple_func(arr, out=out)195    assert all_equal(out, true_result_arr)196    out = np.empty((5, 5), dtype='int')197    simple_func(mg, out=out)198    assert all_equal(out, true_result_mg)199def test_vectorize_2d_lazy():200    # Test vectorization in 1d without data type --> lazy vectorization201    arr = np.empty((2, 5), dtype='int')202    arr[0] = ([-3, -2, -1, 0, 1])203    arr[1] = ([-1, 0, 1, 2, 3])204    mg = sparse_meshgrid([-3, -2, -1, 0, 1], [-1, 0, 1, 2, 3])205    val_1 = (-1, 1)206    val_2 = (2, 1)207    @vectorize208    def simple_func(x):209        return 0 if x[0] < 0 and x[1] > 0 else 1210    true_result_arr = [1, 1, 0, 1, 1]211    true_result_mg = [[1, 1, 0, 0, 0],212                      [1, 1, 0, 0, 0],213                      [1, 1, 0, 0, 0],214                      [1, 1, 1, 1, 1],215                      [1, 1, 1, 1, 1]]216    # Out-of-place217    out = simple_func(arr)218    assert isinstance(out, np.ndarray)219    assert is_int_dtype(out.dtype)220    assert out.shape == (5,)221    assert all_equal(out, true_result_arr)222    out = simple_func(mg)223    assert isinstance(out, np.ndarray)224    assert is_int_dtype(out.dtype)225    assert out.shape == (5, 5)226    assert all_equal(out, true_result_mg)227    assert simple_func(val_1) == 0228    assert simple_func(val_2) == 1229def test_vectorize_callable_class():230    # Test vectorization in 1d without data type --> lazy vectorization231    arr = [[-2, -1, 0, 1, 2]]232    mg = [[-3, -2, -1, 0, 1]]233    val_1 = -1234    val_2 = 2235    # Class with __call__ method236    class CallableClass(object):237        def __call__(self, x):238            return 0 if x < 0 else 1239    vectorized_call = vectorize(CallableClass())240    true_result_arr = [0, 0, 1, 1, 1]241    true_result_mg = [0, 0, 0, 1, 1]242    # Out-of-place...testFunctionDef.py
Source:testFunctionDef.py  
1# foo before comment2def simple_func(foo, bar=5.0, mar=ble, *arg, **args): # on-line3    # this is a comment4    print "myfunc" # foo5def simple_func(foo, bar=5.0, mar=ble, *arg):6    # this is a comment7    print "myfunc" # foo8    9def simple_func(foo, bar=5.0, mar=ble):10    # this is a comment11    print "myfunc" # foo12    13def simple_func(foo, bar=5.0):14    # this is a comment15    print "myfunc" # foo16    17def simple_func(foo, bar):18    # this is a comment19    print "myfunc"20    21# a simple func22def simple_func(foo):23    # this is a comment24    print "myfunc" # foo25# a simple func26def simple_func(): # and a comment27    # this is a comment28    print "myfunc" # foo29    # last comment in simple_func30##r31# foo before comment32def simple_func(foo, bar=5.0, mar=ble, *arg, **args): # on-line33    # this is a comment34    print "myfunc" # foo35def simple_func(foo, bar=5.0, mar=ble, *arg):36    # this is a comment37    print "myfunc" # foo38def simple_func(foo, bar=5.0, mar=ble):39    # this is a comment40    print "myfunc" # foo41def simple_func(foo, bar=5.0):42    # this is a comment43    print "myfunc" # foo44def simple_func(foo, bar):45    # this is a comment46    print "myfunc"47# a simple func48def simple_func(foo):49    # this is a comment50    print "myfunc" # foo51# a simple func52def simple_func(): # and a comment53    # this is a comment54    print "myfunc" # foo55    # last comment in simple_func...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
