How to use is_index method in pandera

Best Python code snippet using pandera_python

command_to_code.py

Source:command_to_code.py Github

copy

Full Screen

1from builtins import Exception2from grammar.if_condition import IfCondition3from grammar.function_definition import FunctionDefinition4from grammar.variable_declaration import VariableDeclaration5from grammar.return_function import ReturnFunction6from grammar.function_call import FunctionCall7from grammar.else_condition import ElseCondition8class CommandToCode:9 def __init__(self):10 self.variable_types = ['integer', 'float', 'string', 'list', 'dictionary', 'variable', 'operation']11 self.compare_types = ['equal to', 'not equal to', 'less than', 'greater than', 'less than or equal to',12 'greater than or ']13 def set_command(self, command: list):14 """15 This function sets the command variable.16 Args:17 command: The list of words which will be converted to code.18 """19 self.command = command20 def remove_command(self):21 """22 This function deletes the current command.23 """24 self.command = None25 def variable_error_check(self):26 """27 This function checks the correctness of variable declaration commands.28 """29 if len(self.command) < 5:30 raise Exception("The Format Is Wrong")31 is_index, point_index = -1, -132 for index, item in enumerate(self.command):33 if item == 'is' and self.command[index + 1] in self.variable_types:34 is_index = index35 if item == 'point':36 point_index = index37 if is_index == -1:38 raise Exception("Is Keyword Not Found")39 if self.command[is_index + 1] not in self.variable_types:40 raise Exception("Variable Type Is Unacceptable")41 if self.command[is_index + 1] == 'integer':42 if not self.command[is_index + 2].isdigit():43 raise Exception("The Value Is Not Number")44 if self.command[is_index + 1] == 'operation':45 if is_index + 2 > len(self.command) - 1:46 raise Exception("Operation Type Not Defined")47 if self.command[is_index + 2] == 'add':48 if is_index + 3 > len(self.command) - 1:49 raise Exception("wrong format")50 if self.command[is_index + 3] not in ['integer', 'float', 'string', 'list', 'variable']:51 raise Exception("Variable Type is Unacceptable")52 if self.command[is_index + 3] == 'integer':53 if not self.command[is_index + 4].isdigit():54 raise Exception("The Value Is Not Number")55 if 'to' not in self.command[is_index + 2:]:56 raise Exception("To keyword not found")57 for index, item in enumerate(self.command):58 if item == 'to':59 to_index = index60 if to_index + 1 > len(self.command) - 1:61 raise Exception("wrong format")62 if self.command[to_index + 1] not in ['integer', 'float', 'string', 'list', 'variable']:63 raise Exception("Variable Type is Unacceptable")64 if to_index + 2 > len(self.command) - 1:65 raise Exception("wrong format")66 if self.command[to_index + 1] == 'integer':67 if not self.command[to_index + 2].isdigit():68 raise Exception("The Value Is Not Number")69 elif self.command[is_index + 2] == 'subtract':70 if is_index + 3 > len(self.command) - 1:71 raise Exception("wrong format")72 if self.command[is_index + 3] not in ['integer', 'float', 'string', 'list', 'variable']:73 raise Exception("Variable Type is Unacceptable")74 if self.command[is_index + 3] == 'integer':75 if not self.command[is_index + 4].isdigit():76 raise Exception("The Value Is Not Number")77 if 'from' not in self.command[is_index + 2:]:78 raise Exception("From keyword not found")79 for index, item in enumerate(self.command):80 if item == 'from':81 from_index = index82 if from_index + 1 > len(self.command) - 1:83 raise Exception("wrong format")84 if self.command[from_index + 1] not in ['integer', 'float', 'string', 'list', 'variable']:85 raise Exception("Variable Type is Unacceptable")86 if from_index + 2 > len(self.command) - 1:87 raise Exception("wrong format")88 if self.command[from_index + 1] == 'integer':89 if not self.command[from_index + 2].isdigit():90 raise Exception("The Value Is Not Number")91 elif self.command[is_index + 2] == 'multiply' or self.command[is_index + 2] == 'divide':92 if is_index + 3 > len(self.command) - 1:93 raise Exception("wrong format")94 if self.command[is_index + 3] not in ['integer', 'float', 'string', 'list', 'variable']:95 raise Exception("Variable Type is Unacceptable")96 if self.command[is_index + 3] == 'integer':97 if not self.command[is_index + 4].isdigit():98 raise Exception("The Value Is Not Number")99 if 'by' not in self.command[is_index + 2:]:100 raise Exception("By keyword not found")101 for index, item in enumerate(self.command):102 if item == 'by':103 by_index = index104 if by_index + 1 > len(self.command) - 1:105 raise Exception("wrong format")106 if self.command[by_index + 1] not in ['integer', 'float', 'string', 'list', 'variable']:107 raise Exception("Variable Type is Unacceptable")108 if by_index + 2 > len(self.command) - 1:109 raise Exception("wrong format")110 if self.command[by_index + 1] == 'integer':111 if not self.command[by_index + 2].isdigit():112 raise Exception("The Value Is Not Number")113 else:114 raise Exception("Operation Type Is Unacceptable")115 def return_error_check(self):116 """117 This function checks the correctness of return commands.118 """119 if len(self.command) < 3:120 raise Exception("The Format Is Wrong")121 if self.command[1] not in self.variable_types + ['variable']:122 raise Exception("Variable Type Is Wrong")123 if self.command[1] != 'variable':124 this_command = self.command125 self.command = ['variable', '_', 'is'] + self.command[1:]126 self.variable_error_check()127 self.command = this_command128 def function_call_error_check(self):129 """130 This function checks the correctness of function call commands.131 """132 if len(self.command) < 9:133 raise Exception("The Format Is Wrong")134 if 'parameters' not in self.command:135 raise Exception("Argument Parameters Is Missed")136 if self.command[-1] != 'parameters':137 raise Exception("End of Parameters Not Found")138 if self.command[-2] != 'of':139 raise Exception("End of Parameters Not Found")140 if self.command[-3] != 'end':141 raise Exception("End of Parameters Not Found")142 def if_condition_error_check(self):143 if self.command[0] == 'else':144 self.command = self.command[1:]145 if len(self.command) < 9:146 raise Exception("The Format Is Wrong")147 if self.command[2] not in ['variable', 'integer', 'float', 'string']:148 raise Exception("Variable Type Is Wrong")149 if self.command[2] == 'integer':150 if not self.command[3].isdigit():151 raise Exception("The Value Is Not Number")152 if self.command[4] != 'is':153 raise Exception("The Format Is Wrong")154 if self.command[2] == 'float':155 if self.command[4] != 'is':156 raise Exception("The Format Is Wrong")157 is_index = -1158 for index, value in enumerate(self.command):159 if value == 'is':160 if self.command[index + 1: index + 3] in [compare_type.split() for compare_type in self.compare_types]\161 or self.command[index + 1: index + 4] in [compare_type.split() for compare_type in self.compare_types]:162 is_index = index163 if is_index == -1:164 raise Exception("Compare Type Is Wrong")165 if " ".join(self.command[is_index + 1: is_index + 3]) in ['equal to', 'less than', 'greater than']:166 second_var_index = is_index + 3167 elif " ".join(self.command[is_index + 1: is_index + 4]) == 'not equal to':168 second_var_index = is_index + 4169 elif " ".join(self.command[is_index + 1: is_index + 6]) in ['less than or equal to', 'greater than or equal to']:170 second_var_index = is_index + 6171 if self.command[second_var_index] not in ['variable', 'integer', 'float', 'string']:172 raise Exception("Variable Type Is Wrong")173 if self.command[second_var_index] == 'integer':174 if not self.command[second_var_index + 1].isdigit():175 raise Exception("The Value Is Not Number")176 def else_condition_error_check(self):177 if len(self.command) != 2:178 raise Exception("The Format Is Wrong")179 def define_function_error_check(self):180 if len(self.command) < 7:181 raise Exception("The Format Is Wrong")182 parametrs_index = -1183 for index, value in enumerate(self.command[:-3]):184 if value == 'parameters':185 parametrs_index = index186 if parametrs_index == -1:187 raise Exception("Parameters keyword not found")188 if self.command[parametrs_index + 1] == 'next':189 raise Exception("The Format Is Wrong")190 for index, value in enumerate(self.command[parametrs_index + 1:-3]):191 if value == 'next':192 if index == len(self.command[parametrs_index + 1:-3]) - 1:193 raise Exception("The Format Is Wrong")194 if not self.command[-1] == 'parameters' and self.command[-2] == 'of' and self.command[-3] == 'end':195 raise Exception("end of parameters not defined")196 def generate_code(self) -> str:197 """198 This function, based on the command, generates the final code of the input command.199 Returns:200 The code of the input command.201 """202 if self.command is None:203 return 'Command has not been assigned.'204 elif self.command[0] == 'variable':205 self.variable_error_check()206 return VariableDeclaration(self.command).code207 elif self.command[0] == 'return':208 self.return_error_check()209 return ReturnFunction(self.command).code210 elif self.command[0] == 'function' and self.command[1] == 'call':211 self.function_call_error_check()212 return FunctionCall(self.command).code213 elif self.command[0] == 'if' and self.command[1] == 'condition':214 self.if_condition_error_check()215 return IfCondition(self.command).code216 elif self.command[0] == 'else' and self.command[1] == 'if' and self.command[2] == 'condition':217 self.if_condition_error_check()218 self.command.insert(0, 'else')219 return IfCondition(self.command).code220 elif self.command[0] == 'else' and self.command[1] == 'condition':221 self.else_condition_error_check()222 return ElseCondition(self.command).code223 elif self.command[0] == 'define' and self.command[1] == 'function':224 self.define_function_error_check()225 return FunctionDefinition(self.command).code226 elif self.command[0] == 'end' and self.command[1] == 'of' and \227 (self.command[2] == 'function' or self.command[2] == 'if' or self.command[2] == 'else'):228 return ''229 else:...

Full Screen

Full Screen

IndicesManager.py

Source:IndicesManager.py Github

copy

Full Screen

1def convert_ln_to_no_comments(line_numbers, indices):2 """3 Arguments:4 line_numbers -- list of line numbers having warnings5 indices -- list of indices corresponding to the source file with no comments6 """7 res = []8 for ln in line_numbers:9 res.append(indices.index(ln) + 1)10 return res11def _is_index_generator(indices, maximum):12 is_index = [1] * (maximum + 1)13 for [fst, lst] in indices:14 for i in range(fst, lst):15 is_index[i] = 016 for i in range(1, len(is_index)):17 is_index[i] += is_index[i-1]18 return is_index19# def convert_ln_to_topformflat(line_numbers, compressed_indices, indices):20# """21# Arguments:22# line_numbers -- list of line numbers having warnings retalive to indices23# compressed_indices -- list of indices corresponding to topformflat24# indices -- list of indices being used in the original file25# """26# if compressed_indices:27# # maximum = max(compressed_indices, key=lambda x: x[1])[1]28# # maximum = max(max(line_numbers), maximum)29# is_index = _is_index_generator(compressed_indices, len(indices))30# res = list(set([is_index[i-1] for i in line_numbers]))31# res.sort()32# return res33# else:34# return [indices[i-1] for i in line_numbers]35def convert_ln_to_original(flatten_indices, compressed_indices, indices):36 """37 Arguments:38 flatten_indices -- indices of the topformflat to convert to source file39 compressed_indices -- indices describing the topformflat file40 indices -- list of indices corresponding to the original file41 """42 if compressed_indices and flatten_indices:43 # maximum = max(compressed_indices, key=lambda x: x[1])[1]44 # maximum = max(max(flatten_indices), maximum)45 tmp_ind = []46 is_index = _is_index_generator(compressed_indices, len(indices))47 for index in flatten_indices:48 for i in range(len(is_index)):49 if index == is_index[i]:50 tmp_ind.append(i + 1)51 # elif index < is_index[i]:52 # break53 # return [indices[i-1] for i in tmp_ind]54 return [indices[i-1] for i in tmp_ind if i <= len(indices)]55 else:56 return [indices[i-1] for i in flatten_indices]57if __name__ == "__main__":58 # assert convert_ln_to_topformflat([100], [[1,50],[52,100]], list(range(1,101))) == [3]59 # assert convert_ln_to_topformflat([3], [[1,2],[3,5]], [1,2,4,5,6,8,9,10]) == [2]60 # assert convert_ln_to_topformflat([7], [[1,2],[3,5]], [1,2,4,5,6,8,9,10]) == [4]61 # assert convert_ln_to_topformflat([7], [], [1,2,4,5,6,8,9,10]) == [9]62 # assert [8] == convert_ln_to_topformflat([13], [[6, 23], [25, 40]], [1, 2, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 147])63 assert convert_ln_to_original([2,3,6,8], [[1,2],[4,6]], [7,8,9,11,13,17,18,19,23,24,25,26]) == [9,11,13,17,23,25]64 assert convert_ln_to_original([], [[1,2],[4,6]], [7,8,9,11,13,17,18,19,23,24,25,26]) == []...

Full Screen

Full Screen

02fad7ab24959e59e8f7791bd9c3a353115ba7c8-<pytest_runtest_setup>-fix.py

Source:02fad7ab24959e59e8f7791bd9c3a353115ba7c8-<pytest_runtest_setup>-fix.py Github

copy

Full Screen

1def pytest_runtest_setup(item):2 fname = item.fspath.strpath3 is_index = fname.endswith('datasets/index.rst')4 if (fname.endswith('datasets/labeled_faces.rst') or is_index):5 setup_labeled_faces()6 elif (fname.endswith('datasets/mldata.rst') or is_index):7 setup_mldata()8 elif (fname.endswith('datasets/rcv1.rst') or is_index):9 setup_rcv1()10 elif (fname.endswith('datasets/twenty_newsgroups.rst') or is_index):11 setup_twenty_newsgroups()12 elif (fname.endswith('tutorial/text_analytics/working_with_text_data.rst') or is_index):13 setup_working_with_text_data()14 elif (fname.endswith('modules/compose.rst') or is_index):...

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