How to use _contains method in pandera

Best Python code snippet using pandera_python

test_distributions.py

Source:test_distributions.py Github

copy

Full Screen

...80 )81 distributions.check_distribution_compatibility(82 EXAMPLE_DISTRIBUTIONS["ilu"], distributions.IntLogUniformDistribution(low=1, high=13)83 )84def test_contains() -> None:85 u = distributions.UniformDistribution(low=1.0, high=2.0)86 assert not u._contains(0.9)87 assert u._contains(1)88 assert u._contains(1.5)89 assert u._contains(2)90 assert not u._contains(2.1)91 lu = distributions.LogUniformDistribution(low=0.001, high=100)92 assert not lu._contains(0.0)93 assert lu._contains(0.001)94 assert lu._contains(12.3)95 assert lu._contains(100)96 assert not lu._contains(1000)97 with warnings.catch_warnings():98 # UserWarning will be raised since the range is not divisible by 2.99 # The range will be replaced with [1.0, 9.0].100 warnings.simplefilter("ignore", category=UserWarning)101 du = distributions.DiscreteUniformDistribution(low=1.0, high=10.0, q=2.0)102 assert not du._contains(0.9)103 assert du._contains(1.0)104 assert du._contains(3.5)105 assert du._contains(6)106 assert du._contains(9)107 assert not du._contains(9.1)108 assert not du._contains(10)109 iu = distributions.IntUniformDistribution(low=1, high=10)110 assert not iu._contains(0.9)111 assert iu._contains(1)112 assert iu._contains(4)113 assert iu._contains(6)114 assert iu._contains(10)115 assert not iu._contains(10.1)116 assert not iu._contains(11)117 # IntUniformDistribution with a 'step' parameter.118 with warnings.catch_warnings():119 # UserWarning will be raised since the range is not divisible by 2.120 # The range will be replaced with [1, 9].121 warnings.simplefilter("ignore", category=UserWarning)122 iuq = distributions.IntUniformDistribution(low=1, high=10, step=2)123 assert not iuq._contains(0.9)124 assert iuq._contains(1)125 assert iuq._contains(4)126 assert iuq._contains(6)127 assert iuq._contains(9)128 assert not iuq._contains(9.1)129 assert not iuq._contains(10)130 c = distributions.CategoricalDistribution(choices=("Roppongi", "Azabu"))131 assert not c._contains(-1)132 assert c._contains(0)133 assert c._contains(1)134 assert c._contains(1.5)135 assert not c._contains(3)136 ilu = distributions.IntUniformDistribution(low=2, high=12)137 assert not ilu._contains(0.9)138 assert ilu._contains(2)139 assert ilu._contains(4)140 assert ilu._contains(6)141 assert ilu._contains(12)142 assert not ilu._contains(12.1)143 assert not ilu._contains(13)144 iluq = distributions.IntLogUniformDistribution(low=2, high=7)145 assert not iluq._contains(0.9)146 assert iluq._contains(2)147 assert iluq._contains(4)148 assert iluq._contains(5)149 assert iluq._contains(6)150 assert not iluq._contains(7.1)151 assert not iluq._contains(8)152def test_empty_range_contains() -> None:153 u = distributions.UniformDistribution(low=1.0, high=1.0)154 assert not u._contains(0.9)155 assert u._contains(1.0)156 assert not u._contains(1.1)157 lu = distributions.LogUniformDistribution(low=1.0, high=1.0)158 assert not lu._contains(0.9)159 assert lu._contains(1.0)160 assert not lu._contains(1.1)161 du = distributions.DiscreteUniformDistribution(low=1.0, high=1.0, q=2.0)162 assert not du._contains(0.9)163 assert du._contains(1.0)164 assert not du._contains(1.1)165 iu = distributions.IntUniformDistribution(low=1, high=1)166 assert not iu._contains(0)167 assert iu._contains(1)168 assert not iu._contains(2)169 iuq = distributions.IntUniformDistribution(low=1, high=1, step=2)170 assert not iuq._contains(0)171 assert iuq._contains(1)172 assert not iuq._contains(2)173 ilu = distributions.IntUniformDistribution(low=1, high=1)174 assert not ilu._contains(0)175 assert ilu._contains(1)176 assert not ilu._contains(2)177 iluq = distributions.IntUniformDistribution(low=1, high=1, step=2)178 assert not iluq._contains(0)179 assert iluq._contains(1)180 assert not iluq._contains(2)181def test_single() -> None:182 with warnings.catch_warnings():183 # UserWarning will be raised since the range is not divisible by step.184 warnings.simplefilter("ignore", category=UserWarning)185 single_distributions: List[distributions.BaseDistribution] = [186 distributions.UniformDistribution(low=1.0, high=1.0),187 distributions.LogUniformDistribution(low=7.3, high=7.3),188 distributions.DiscreteUniformDistribution(low=2.22, high=2.22, q=0.1),189 distributions.DiscreteUniformDistribution(low=2.22, high=2.24, q=0.3),190 distributions.IntUniformDistribution(low=-123, high=-123),191 distributions.IntUniformDistribution(low=-123, high=-120, step=4),192 distributions.CategoricalDistribution(choices=("foo",)),193 distributions.IntLogUniformDistribution(low=2, high=2),194 ]...

Full Screen

Full Screen

test_exec.py

Source:test_exec.py Github

copy

Full Screen

...15from iptest.assert_util import *16##17## to test how exec related to globals/locals18##19def _contains(large, small):20 for (key, value) in list(small.items()):21 Assert(large[key] == value)22def _not_contains(dict, *keylist):23 for key in keylist:24 Assert(key not in dict)25## exec without in something26x = 127y = "hello"28_contains(globals(), {"x":1, "y":"hello"})29_contains(locals(), {"x":1, "y":"hello"})30exec("x, y")31_contains(globals(), {"x":1, "y":"hello"})32_contains(locals(), {"x":1, "y":"hello"})33## exec with custom globals34# -- use global x, y; assign35g1 = {'x':2, 'y':'world'}36exec("global x; x, y; x = 4", g1)37_contains(globals(), {"x":1, "y":"hello"})38_contains(locals(), {"x":1, "y":"hello"})39_contains(g1, {"x":4, "y":"world"})40exec("global x; x, y; x = x + 4", g1)41_contains(g1, {"x":8})42# -- declare global43exec("global z", g1)44_not_contains(globals(), 'z')45_not_contains(locals(), 'z')46_not_contains(g1, 'z')47# -- new global48exec("global z; z = -1", g1)49_not_contains(globals(), 'z')50_not_contains(locals(), 'z')51_contains(g1, {'z':-1})52# y is missing in g253g2 = {'x':3}54try:55 exec("x, y", g2)56except NameError: pass57else: Assert(False, "should throw NameError exception")58exec("y = 'ironpython'", g2)59_contains(g2, {"x":3, "y":"ironpython"})60_contains(globals(), {"y":"hello"})61_contains(locals(), {"y":"hello"})62## exec with custom globals, locals63g = {'x': -1, 'y': 'python' }64l = {}65# use global66exec("if x != -1: throw", g, l)67exec("if y != 'python': throw", g, l)68_not_contains(l, 'x', 'y')69# new local70exec("x = 20; z = 2", g, l)71_contains(g, {"x":-1, "y":"python"})72_contains(l, {"x":20, "z":2})73# changes74exec("global y; y = y.upper(); z = -2", g, l)75_contains(g, {'x': -1, 'y': 'PYTHON'})76_contains(l, {'x': 20, 'z': -2})77# new global78exec("global w; w = -2", g, l)79_contains(g, {'x': -1, 'y': 'PYTHON', 'w': -2})80_contains(l, {'x': 20, 'z': -2})81# x in both g and l; use it82exec("global x; x = x - 1", g, l)83_contains(g, {'x': -2, 'y': 'PYTHON', 'w': -2})84_contains(l, {'x': 20, 'z': -2})85exec("x = x + 1", g, l)86_contains(g, {'x': -2, 'y': 'PYTHON', 'w': -2})87_contains(l, {'x': 21, 'z': -2})88## Inside Function: same as last part of previous checks89def InsideFunc():90 g = {'x': -1, 'y': 'python' }91 l = {}92 # use global93 exec("if x != -1: throw", g, l)94 exec("if y != 'python': throw", g, l)95 _not_contains(l, 'x', 'y')96 # new local97 exec("x = 20; z = 2", g, l)98 _contains(g, {"x":-1, "y":"python"})99 _contains(l, {"x":20, "z":2})100 # changes101 exec("global y; y = y.upper(); z = -2", g, l)102 _contains(g, {'x': -1, 'y': 'PYTHON'})103 _contains(l, {'x': 20, 'z': -2})104 # new global105 exec("global w; w = -2", g, l)106 _contains(g, {'x': -1, 'y': 'PYTHON', 'w': -2})107 _contains(l, {'x': 20, 'z': -2})108 # x in both g and l; use it109 exec("global x; x = x - 1", g, l)110 _contains(g, {'x': -2, 'y': 'PYTHON', 'w': -2})111 _contains(l, {'x': 20, 'z': -2})112 exec("x = x + 1", g, l)113 _contains(g, {'x': -2, 'y': 'PYTHON', 'w': -2})114 _contains(l, {'x': 21, 'z': -2})115InsideFunc()116unique_global_name = 987654321117class C:118 exec('a = unique_global_name')119 exec("if unique_global_name != 987654321: raise AssertionError('cannott see unique_global_name')")120AreEqual(C.a, 987654321)121def f():122 exec("if unique_global_name != 987654321: raise AssertionError('cannot see unique_global_name')")123 def g(): exec("if unique_global_name != 987654321: raise AssertionError('cannot see unique_global_name')")124 g()125f()126# exec tests127# verify passing a bad value throws...128try:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful