How to use __isfloat method in autotest

Best Python code snippet using autotest_python

data_structure.py

Source:data_structure.py Github

copy

Full Screen

...320 321 if False:322 pass323 else: 324 if self.__isfloat(item):325 assert self.shape[1] == 1 , "Cannot check less than on more than one column"326 indexes = [i for i,element in enumerate(self.aslist) if float(element) < float(item)]327 328 #Returns False if no item is matched or list of index if some items are matched329 if len(indexes) == 0:330 return False331 else:332 return indexes333 else:334 assert False, "item should be convertible datatype or a dataFrame of same shape "335 336 def __ne__(self,item):337 '''Implementing '!=' for dataFrame '''338 339 340 value = (self == item)341 342 if type(value) == bool:343 return (not value)344 elif type(value)==list:345 indexes = [i for i in range(self.num_rows) if i not in value]346 return indexes347 348 def __truediv__(self, item):349 '''Implementing '/' operator for dataFrame'''350 351 assert self.shape[1] == 1,"Cannot call / on more than one column"352 truediv_array = [['']]*self.num_rows353 354 #Simple broadcasting355 if self.__isfloat(item):356 for i in range(self.num_rows):357 truediv_array[i] = [round(float(self[i])/float(item),4)] if self.__isfloat(self[i]) else [float('NaN')]358 truediv_array.insert(0,[self.columns[0]])359 return dataFrame(truediv_array)360 361 #When item is a dataFrame362 #Note that column name of the returned dataframe is the column name of first operand363 elif type(item) == type(dataFrame([[''],['']])):364 assert self.shape == item.shape , "No of rows mismatched"365 for i in range(self.num_rows):366 truediv_array[i] = [round(float(self[i])/float(item[i]),4)] if (self.__isfloat(self[i]) and self.__isfloat(item[i])) else [float('NaN')]367 truediv_array.insert(0,[self.columns[0]])368 return dataFrame(truediv_array)369 370 else:371 assert False,"item should be float convertible datatype or a dataFrame of same shape"372 373 374 def __add__(self, item):375 '''Implementing '+' operator for dataFrame'''376 377 assert self.shape[1] == 1,"Cannot call + on more than one column"378 add_array = [['']]*self.num_rows379 380 #Simple broadcasting381 if self.__isfloat(item):382 for i in range(self.num_rows):383 add_array[i] = [round(float(self[i])+float(item),4)] if self.__isfloat(self[i]) else [float('NaN')]384 add_array.insert(0,[self.columns[0]])385 return dataFrame(add_array)386 387 #When item is a dataFrame388 elif type(item) == type(dataFrame([[''],['']])):389 assert self.shape == item.shape , "No of rows mismatched"390 for i in range(self.num_rows):391 add_array[i] = [round(float(self[i])+float(item[i]),4)] if (self.__isfloat(self[i]) and self.__isfloat(item[i])) else [float('NaN')]392 add_array.insert(0,[self.columns[0]])393 return dataFrame(add_array)394 395 else:396 assert False,"item should be convertible datatype or a dataFrame of same shape"397 398 def __sub__(self, item):399 '''Implementing '-' operator for dataFrame'''400 401 assert self.shape[1] == 1,"Cannot call - on more than one column"402 sub_array = [['']]*self.num_rows403 404 #Simple broadcasting405 if self.__isfloat(item):406 for i in range(self.num_rows):407 sub_array[i] = [round(float(self[i])-float(item),4)] if self.__isfloat(self[i]) else [float('NaN')]408 sub_array.insert(0,[self.columns[0]])409 return dataFrame(sub_array)410 411 #When item is a dataFrame412 #Note that column name of the returned dataframe is the column name of first operand413 elif type(item) == type(dataFrame([[''],['']])):414 assert self.shape == item.shape , "No of rows mismatched"415 for i in range(self.num_rows):416 sub_array[i] = [round(float(self[i])-float(item[i]),4)] if (self.__isfloat(self[i]) and self.__isfloat(item[i])) else [float('NaN')]417 sub_array.insert(0,[self.columns[0]])418 return dataFrame(sub_array)419 420 421 else:422 assert False,"item should be float convertible datatype or a dataFrame of same shape"423 424 def __pow__(self, item):425 '''Implementing '**' operator for dataFrame'''426 427 assert self.shape[1] == 1,"Cannot call - on more than one column"428 pow_array = [['']]*self.num_rows429 430 #Simple broadcasting431 if self.__isfloat(item):432 for i in range(self.num_rows):433 pow_array[i] = [round(float(self[i])**float(item),4)] if self.__isfloat(self[i]) else [float('NaN')]434 pow_array.insert(0,[self.columns[0]])435 return dataFrame(pow_array)436 437 #When item is a dataFrame438 #Note that column name of the returned dataframe is the column name of first operand439 elif type(item) == type(dataFrame([[''],['']])):440 assert self.shape == item.shape , "No of rows mismatched"441 for i in range(self.num_rows):442 pow_array[i] = [round(float(self[i])**float(item[i]),4)] if (self.__isfloat(self[i]) and self.__isfloat(item[i])) else [float('NaN')]443 pow_array.insert(0,[self.columns[0]])444 return dataFrame(pow_array)445 446 447 else:448 assert False,"item should be float convertible datatype or a dataFrame of same shape"449 450 451 452 def __find_columns(self,column_name):453 '''returns the list of all indexes for the given column name present in the dataFrame'''454 455 assert column_name in self.columns , "Invalid Column name"456 idxes = []457 for i in range(len(self.columns)):458 if column_name == self.columns[i]:459 idxes.append(i)460 return idxes461 462 463 def __display_dict(self,dic):464 max_length = len(max(list(dic.keys()),key = len))465 for elem in dic:466 print('{0:<{1}} : {2}'.format(elem,max_length,dic[elem]))467 print('\n') 468 469 470 def __isfloat(self,x):471 try:472 float(x)473 return True474 except ValueError:475 return False476 except TypeError:477 return False478 479 #Bi-type480 def __find_first_index_ofTwo(self,value):481 '''Uses bisection search algorithm to find the index482 483 NOTE: Only works if type and non-type elements are present484 where the given value is type and all others are non type485 and type elements always occur together at last'''486 487 assert self.shape[1] == 1,"Cannot find index on more than one column with this method"488 low = 0 489 lst = self.aslist490 high = len(lst)-1491 idx = -1492 493 #Bisection implementation494 while low <= high:495 mid = (high+low)//2496 497 if self[mid] == value:498 idx = mid499 high = mid-1500 501 elif self[mid] != value:502 low = mid+1503 504 505 if idx != -1:506 return idx507 else:508 assert False, "Element Not Found"509 510 511 def change_columnName(self,name):512 if isinstance(name,list):513 assert self.num_columns == len(name) , "Number of columns mismatched"514 self.__rows[0] = name515 else:516 assert False, "Argument for column should be given as a list"517 518 519 def value_counts(self):520 assert self.shape[1] == 1,"Cannot call value_counts on more than one column"521 column_items = self.aslist522 523 item2counts = {}524 for column in column_items:525 if column == '' or column == 'NaN':526 continue527 if str(column) in item2counts:528 item2counts[str(column)]+=1529 else:530 item2counts[str(column)] = 1531 item2counts_ordered = OrderedDict(sorted(item2counts.items(), key = lambda x:-x[1]))532 self.__display_dict(item2counts_ordered)533 534 def diff(self):535 assert self.shape[1] == 1,"Cannot call diff on more than one column"536 537 diff_array = [['']]*self.num_rows538 for i in range(self.num_rows):539 if (i-1 >=0) and self.__isfloat(self.__getitem__(i)) and self.__isfloat(self.__getitem__(i-1)):540 diff_array[i] = [round(float(self.__getitem__(i))-float(self.__getitem__(i-1)),4)]541 else:542 diff_array[i] = ['NaN']543 diff_array.insert(0,[self.columns[0]])544 return dataFrame(diff_array)545 546 def sum(self,ignore_nons = True):547 '''Calculates the sum of elements of the column'''548 549 assert self.shape[1] == 1,"Cannot call sum on more than one column"550 if ignore_nons:551 sum_array = [float(self[i]) for i in range(self.num_rows) if (not math.isnan(float(self[i])) and self[i] not in ['NaN'] and self.__isfloat(self[i]))]552 else:553 return round(float(sum(self.aslist)),4)554 return round(float(sum(sum_array)),4)555 def num_items(self,ignore_nons = True):556 '''Calculates the sum of elements of the column'''557 558 assert self.shape[1] == 1,"Cannot call sum on more than one column"559 if ignore_nons:560 array = [float(self[i]) for i in range(self.num_rows) if (not math.isnan(float(self[i])) and self[i] not in ['NaN'] and self.__isfloat(self[i]))]561 else:562 return len(self.num_rows)563 return len(array)564 565 566 567 568 def find_firstOfTwo(self, value):569 '''Finds the first index of given value'''570 571 return self.__find_first_index_ofTwo(value=value)572 573 def find_last_validOfTwo(self):574 '''Only 'NaN' are counted as Invalid...

Full Screen

Full Screen

rootError.py

Source:rootError.py Github

copy

Full Screen

1from tkinter import messagebox23class Errors:4 @staticmethod5 def __checkNumber(number):6 if number.rfind('-') not in [0, -1] or number in ['.', '-'] or number == '': return False7 if number.count('.') not in [0, 1] or '-.' in number: return False8 for elem in number:9 if elem not in '0123456789.-':10 return False11 return True1213 @staticmethod14 def __isFloat(number):15 try:16 number = float(number)17 return True18 except:19 return False2021 @staticmethod22 def invalidList(list):23 listCol = {0: 'начало', 1: 'конец', 2: 'шаг', 3: 'точность', 4: 'количество итераций'}24 if list == ['', '', '', '', '']:25 messagebox.showinfo('Error', 'Вы не ввели данные')26 return False2728 for i, number in enumerate(list):29 if i not in [3, 4] and not Errors.__isFloat(number):30 messagebox.showinfo('Error', f'Вы некорректно ввели {listCol[i]}')31 return False32 if i in [3, 4] and (not Errors.__isFloat(number) or float(number) <= 0):33 messagebox.showinfo('Error', f'Вы некорректно ввели {listCol[i]}')34 return False3536 if float(list[0]) < float(list[1]) and float(list[2]) <= 0:37 messagebox.showinfo('Error', 'Отрицательный шаг при левой границе меньшей правой')38 return False39 elif float(list[0]) > float(list[1]) and float(list[2]) >= 0:40 messagebox.showinfo('Error', 'Положительный шаг при левой границе большей правой')41 return False42 elif float(list[0]) == float(list[1]):43 messagebox.showinfo('Error', 'Начало и конец отрезка совпадают')44 return False45 elif float(list[2]) == 0:46 messagebox.showinfo('Error', 'Шаг равен 0')47 return False4849 if (float(list[3]) > 0.01):50 messagebox.showinfo('Error', 'Слишком большая точность')51 return False ...

Full Screen

Full Screen

Method.py

Source:Method.py Github

copy

Full Screen

...8 def get_function_value(self, variable_values):9 if len(self.mathematical_model.variables) == len(variable_values):10 obj_function = self.mathematical_model.objective_function11 for i in range(0, len(variable_values)):12 if self.__isfloat(variable_values[i]):13 obj_function = obj_function.replace(self.mathematical_model.variables[i], str(variable_values[i]))14 return eval(obj_function)15 else:16 print('Error >>> Количество переменных не совпадает.')17 return False18 def is_satisfies_constraints(self, variable_values):19 if len(self.mathematical_model.variables) == len(variable_values):20 constraints = self.mathematical_model.constraints21 for constraint in constraints:22 for i in range(0, len(variable_values)):23 if self.__isfloat(variable_values[i]):24 constraint = constraint.replace(self.mathematical_model.variables[i], str(variable_values[i]))25 if eval(constraint) == False:26 return False27 return True28 else:29 print('Error >>> Количество переменных не совпадает.')30 return False31 def get_constraints_function_value(self, variable_values):32 if self.is_satisfies_constraints(variable_values):33 return self.get_function_value(variable_values)34 else:35 return False 36 def __isfloat(self, value):37 try:38 float(value)39 return True40 except ValueError:41 return False42 def print_history(self):43 for line in self.list_result_history:44 print(line)45 def generate_result(self):46 point_string = ""47 for j in range(0, len(self.mathematical_model.variables)):48 point_string = point_string + self.mathematical_model.variables[j] + " = %.2f, " % self.result[j]49 point_string = point_string + "f = %.3f" % self.result[len(self.result) - 1]50 return point_string

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 autotest 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