How to use validate_lazy method in pandera

Best Python code snippet using pandera_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...82 def __init__(self, params):83 self.json = params84 85 if self.is_lazy(params):86 self.validate_lazy(params)87 self.initialise_lazy(params)88 89 self.validate()90 91 def validate_lazy(self, params):92 for key in ForceModel.compulsory_keys_lazy:93 try:94 params[key]95 except KeyError:96 raise InvalidArgumentError("Compulsory property '" + key + "' was not specified.")97 98 def initialise_lazy(self, params):99 if params['type'] == ForceModelType.HOOKIAN:100 self.initialise_lazy_hookian(params)101 else:102 s = """hookian force model initialisation is the only type to have been103 implemented in the wrapper so far - you may specify your own herzian 104 spring/damping values."""105 raise Exception(s)...

Full Screen

Full Screen

pgn.py

Source:pgn.py Github

copy

Full Screen

...34 @pgn.setter35 def pgn(self, pgn):36 """Check and set the pgn property."""37 pgn = re.sub(r'\ +', ' ', pgn.strip())38 self.validate_lazy(pgn)39 self._pgn = pgn40 self._parse()41 def _parse(self):42 moves = ''43 for line in self.pgn.split("\n"):44 line = line.strip()45 if line.startswith('['):46 line = line.strip("[]").split(' ')47 attr = line[0].lower().strip()48 value = " ".join(line[1:]).strip().strip('"')49 if attr not in self._VALID_TAGS and not self.lazy:50 message = 'Tags "{0}" not in valid tags list: {1}'51 raise ValueError(message.format(attr,52 str(self._VALID_TAGS)))53 # set in tags dict for safe access of tags54 self.tags[attr] = value55 # set as attribute of object for simple access of known tags56 setattr(self, attr, value)57 else: # moves58 if line != '':59 moves += line + ' '60 self.moves_string = re.sub(r'\s+', ' ', moves.strip())61 @staticmethod62 def validate_lazy(pgn):63 """Validate the pgn string."""64 if not pgn.startswith("[Event"):65 raise TypeError("Not a valid PGN. Doesn't start with Event attr.")66def get_pgns(pgn_string):67 """Return a list of Game instance based on the pgn string."""68 pgns = []69 current_pgn = ''70 for line in pgn_string.strip().split("\n"):71 if line.startswith('[Event'):72 if current_pgn != '':73 pgn = Game(current_pgn)74 pgns.append(pgn)75 current_pgn = ''76 current_pgn += line + "\n"...

Full Screen

Full Screen

run.py

Source:run.py Github

copy

Full Screen

1#!/usr/bin/env python 2import os3import json as js4import argparse as argp5import pickle as pk6import torch as tc7import torch.nn as nn8from torch.utils.data import DataLoader9from localatt.get_class_weight import get_class_weight10from localatt.lld_dataset import lld_dataset11from localatt.lld_dataset import lld_collate_fn12from localatt.validate_lazy import validate_war_lazy 13from localatt.validate_lazy import validate_uar_lazy14from localatt.localatt import localatt15from localatt.train import train16from localatt.train import validate_loop_lazy17device=tc.device("cuda:0" if tc.cuda.is_available() else "cpu")18pars = argp.ArgumentParser()19pars.add_argument('--propjs', help='property json')20with open(pars.parse_args().propjs) as f:21 #p = js.load(f.read())22 p = js.load(f)23print(js.dumps(p, indent=4))24with open(p['fulldata'], 'rb') as f:25 full_utt_lld = pk.load(f)26train_utt_lab_path = p['dataset']+'/train_utt_lab.list'27dev_utt_lab_path = p['dataset']+'/dev_utt_lab.list'28eval_utt_lab_path = p['dataset']+'/eval_utt_lab.list'29model_pth = p['model']30log = p['log']31lr=p['lr']32ephs=p['ephs']33bsz=p['bsz']34 35with open(p['dataset']+'/idx_label.json') as f:36 tgt_cls = js.load(f) # target classes37featdim=p['featdim']38nhid=p['nhid']39measure=p['measure']40ncell=p['ncell']41nout = len(tgt_cls)42cls_wgt = get_class_weight(train_utt_lab_path,device) # done.43print('class weight:', cls_wgt)44valid_lazy = {'uar': validate_uar_lazy,45 'war': validate_war_lazy } # done.46# loading47trainset = lld_dataset(full_utt_lld, train_utt_lab_path, cls_wgt, device)48devset = lld_dataset(full_utt_lld, dev_utt_lab_path, cls_wgt, device)49evalset = lld_dataset(full_utt_lld, eval_utt_lab_path, cls_wgt, device)50_collate_fn = lld_collate_fn(device=device) # done.51trainloader = DataLoader(trainset, bsz, collate_fn=_collate_fn)52devloader = DataLoader(devset, bsz, collate_fn=_collate_fn)53evalloader = DataLoader(evalset, bsz, collate_fn=_collate_fn)54# training55model = localatt(featdim, nhid, ncell, nout) # done.56model.to(device)57print(model)58crit = nn.CrossEntropyLoss(weight=cls_wgt)59if os.path.exists(model_pth):60 print(model_pth, 'already exists')61else:62 optim = tc.optim.Adam(model.parameters(), lr=0.00005)63 _val_lz = valid_lazy[measure](crit=crit)64 _val_loop_lz = validate_loop_lazy(name='valid', 65 loader=devloader,log=log)66 trained = train(model, trainloader, 67 _val_lz, _val_loop_lz, crit, optim, ephs, log)68 tc.save(trained.state_dict(), model_pth)69model.load_state_dict(tc.load(model_pth))70_val_lz = valid_lazy[measure](model=model, crit=crit)71# testing...

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