How to use _equal method in pandera

Best Python code snippet using pandera_python

test_decorators.py

Source:test_decorators.py Github

copy

Full Screen

...3import os4import unittest5import numpy6from atooms.trajectory import TrajectoryXYZ7def _equal(system1, system2):8 for p1, p2 in zip(system1.particle, system2.particle):9 if p1.species != p2.species:10 print(p1.species, p2.species)11 return False12 return True13class TestDecorators(unittest.TestCase):14 Trajectory = TrajectoryXYZ15 def setUp(self):16 self.finp = '/tmp/test_decorators.xyz'17 with open(self.finp, 'w') as fh:18 fh.write("""\19220step:1 cell:6.0,6.0,6.021A 1.0 -1.0 0.022A 2.9 -2.9 0.023224step:2 cell:6.0,6.0,6.025A 1.1 -1.1 0.026A -2.9 -2.9 0.027228step:3 cell:6.0,6.0,6.029A 1.2 -1.2 0.030A -2.9 2.9 0.031232step:4 cell:6.0,6.0,6.033A 1.2 -1.2 0.034A -2.9 2.9 0.035""")36 def test_unfolded_jump(self):37 from atooms.trajectory.decorators import Unfolded38 with self.Trajectory(self.finp) as th:39 with Unfolded(th) as tu:40 self.assertEqual(list(tu[2].particle[1].position), [3.1, -3.1, 0.0]) # unfolded41 self.assertEqual(list(th[2].particle[1].position), [-2.9, 2.9, 0.0]) # original42 def test_sliced(self):43 from atooms.trajectory.decorators import Sliced44 with Sliced(self.Trajectory(self.finp), slice(0, 2, 1)) as th:45 self.assertEqual(th.steps, [1, 2])46 self.assertEqual(list(th[-1].particle[0].position), [1.1, -1.1, 0.0])47 self.assertEqual(list(th[-1].particle[1].position), [-2.9, -2.9, 0.0])48 def test_callback_args(self):49 def cbk_1(system, scale):50 for p in system.particle:51 p.position *= scale52 return system53 def cbk_2(system, offset):54 for p in system.particle:55 p.position -= offset56 return system57 def cbk_3(system, memory):58 """Callback that modifies a mutable."""59 memory.append(1)60 return system61 memo = []62 with self.Trajectory(self.finp) as th:63 th.register_callback(cbk_1, 2.0)64 th.register_callback(cbk_2, offset=1.0)65 th.register_callback(cbk_3, memo)66 self.assertEqual(th.steps, [1, 2, 3, 4])67 self.assertEqual(list(th[-1].particle[0].position),68 [1.2 * 2 - 1.0, -1.2 * 2 - 1.0, 0.0 * 2 - 1.0])69 self.assertEqual(memo, [1])70 def test_change_species(self):71 from copy import deepcopy72 from atooms.system import System, Particle73 system_A = System([Particle(species='A'), Particle(species='B')])74 system_C = System([Particle(species='0'), Particle(species='1')])75 system_F = System([Particle(species='1'), Particle(species='2')])76 from atooms.trajectory.decorators import change_species77 # DO nothing here78 self.assertTrue(_equal(system_A, change_species(deepcopy(system_A), 'A')))79 self.assertTrue(_equal(system_C, change_species(deepcopy(system_C), 'C')))80 self.assertTrue(_equal(system_F, change_species(deepcopy(system_F), 'F')))81 # Change82 self.assertTrue(_equal(system_C, change_species(deepcopy(system_A), 'C')))83 self.assertTrue(_equal(system_F, change_species(deepcopy(system_A), 'F')))84 self.assertTrue(_equal(system_A, change_species(deepcopy(system_C), 'A')))85 self.assertTrue(_equal(system_F, change_species(deepcopy(system_C), 'F')))86 self.assertTrue(_equal(system_A, change_species(deepcopy(system_F), 'A')))87 self.assertTrue(_equal(system_C, change_species(deepcopy(system_F), 'C')))88 def tearDown(self):89 os.remove(self.finp)90if __name__ == '__main__':...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

2import copy3from .. import BasicMeasure, accumulate4class TestDempster(unittest.TestCase):5 def test_can_do_dempster_shafer(self):6 def _equal(a, b): # fuzzy equal required to test floats7 self.assertAlmostEqual(a, b, places=7)8 subjectA = 'Anna'9 subjectB = 'Bob'10 subjectC = 'Clara'11 # m1(A, C) = 0.8, m1(Omega) = 0.212 m1 = BasicMeasure({subjectA, subjectB, subjectC})13 m1.add_entry({subjectA, subjectC}, 0.8)14 with self.assertRaises(Exception):15 m1.add_entry({subjectC, subjectA}, 0.7)16 _equal(m1.get_measure('Omega'), 0.2)17 _equal(m1.get_measure({subjectA, subjectB, subjectC}), 0.2)18 with self.subTest('Can add an alternative entry'):19 mX = copy.deepcopy(m1)20 mX.add_entry(subjectB, 0.1)21 _equal(mX.get_measure('Omega'), 0.1)22 _equal(mX.get_measure(subjectB), 0.1)23 _equal(m1.get_belief('Omega'), 1)24 _equal(m1.get_belief({subjectA, subjectC}), 0.8)25 # Doubt = Belief(Omega \ X)26 _equal(m1.get_doubt(subjectA), 0)27 _equal(m1.get_doubt(subjectB), 0.8)28 _equal(m1.get_doubt('Omega'), 0)29 _equal(m1.get_plausibility('Omega'), 1)30 _equal(m1.get_plausibility(subjectA), 1)31 _equal(m1.get_plausibility(subjectB), 0.2)32 # m2(C) = 0.6, m2(Omega) = 0.433 m2 = BasicMeasure({subjectA, subjectB, subjectC})34 m2.add_entry(subjectC, 0.6)35 _equal(m2.get_measure('Omega'), 0.4)36 m1m2 = accumulate(m1, m2)37 self.assertIsInstance(m1m2, BasicMeasure)38 _equal(m1m2.get_belief('Omega'), 1)39 """ m1(A,C) = 0.8 m1(Om) 0.240 m2(C) = 0.6 C = 0.48 C = 0.1241 m2(Om) = 0.4 A,C = 0.32 Om = 0.0842 """43 _equal(m1m2.get_measure(subjectA), 0)44 _equal(m1m2.get_measure({subjectA, subjectC}), 0.32)45 _equal(m1m2.get_measure(subjectC), 0.6)46 _equal(m1m2.get_measure(subjectB), 0)47 _equal(m1m2.get_measure('Omega'), 0.08)48 _equal(m1m2.get_belief(subjectA, subjectB), 0)49 _equal(m1m2.get_belief(subjectA, subjectC),50 0.48 + 0.32 + 0.12)51 _equal(m1m2.get_plausibility(subjectA, subjectB), 0.4)52 _equal(m1m2.get_plausibility(subjectA, subjectC), 1)53 _equal(m1m2.get_plausibility('Omega'), 1)54 _equal(m1m2.get_plausibility(subjectB), 0.08)55 # can resolve conflicts56 m3 = BasicMeasure({subjectA, subjectB, subjectC})57 m3.add_entry(subjectB, 0.5)58 m1m2m3 = accumulate(m1m2, m3)59 """ m1m2(A,C)=0.32 m1m2(C)=0.6 m1m2(Om)=0.0860 m3(B)=0.5 {}=0.16 {}=0.3 B=0.0461 m3(Om)=0.5 A,C=0.16 C=0.3 Om=0.0462 0.32 0.6 0.0863 """64 correct_factor = 1 / (1 - 0.46)65 _equal(m1m2m3.get_measure(subjectA), 0)66 _equal(m1m2m3.get_measure(subjectA, subjectC), 0.16*correct_factor)67 _equal(m1m2m3.get_measure(subjectC), 0.3*correct_factor)68 _equal(m1m2m3.get_measure(subjectB), 0.04*correct_factor)69 _equal(m1m2m3.get_measure('Omega'), 0.04*correct_factor)70 mInvalid = BasicMeasure({subjectA, subjectB}) # different domain71 mInvalid.add_entry(subjectA, 0.8)72 with self.assertRaises(Exception):...

Full Screen

Full Screen

response_helper_test.py

Source:response_helper_test.py Github

copy

Full Screen

1from shared_test.response_helper import _equal, ignored2def test_empty_array_is_only_equal_to_empty_array():3 assert not _equal([], dict())4 assert not _equal([], dict(a=1))5 assert not _equal([], [1])6 assert not _equal([], 'string')7 assert not _equal(dict(), [])8 assert not _equal(dict(a=1), [])9 assert not _equal([1], [])10 assert not _equal('string', [])11 assert _equal([], [])12def test_empty_dict_is_only_equal_to_empty_dict():13 assert not _equal(dict(), dict(a=1))14 assert not _equal(dict(), [])15 assert not _equal(dict(), [1])16 assert not _equal(dict(), 'string')17 assert not _equal(dict(a=1), dict())18 assert not _equal([], dict())19 assert not _equal([1], dict())20 assert not _equal('string', dict())21 assert _equal(dict(), dict())22def test_equal_dicts():23 value = dict(a=dict(b=['b', 1, 2.0, [1, 2, 3, 4]]))24 assert _equal(value, value)25def test_equal_arrays():26 value = [1, 2, 3, dict(a=dict(b=['b', 1, 2.0, [1, 2, 3, 4]]))]27 assert _equal(value, value)28def assert_equal_strings():29 assert _equal('abc', 'abc')30def assert_equal_integers():31 assert _equal(1, 1)32def test_equal_with_ignored_values():33 expected = dict(34 id=ignored,35 array=ignored,36 dict=ignored,37 a=dict(38 b=[ignored, 1, ]39 )40 )41 actual = dict(42 id=1,43 array=[6, 7],44 dict=dict(o=0),45 a=dict(46 b=['string', 1, ]47 )48 )...

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