Best Python code snippet using gabbi_python
annotation.py
Source:annotation.py
...74 self.df_b = df_b75 self.dataset_a_name = dataset_a_name76 self.dataset_b_name = dataset_b_name77 def _get_value(self, df, loc_x, loc_y, *args, **kwargs):78 return self._cast_value(df.at[loc_x, loc_y], *args, **kwargs)79 @staticmethod80 def _cast_value(value, na_value=None):81 if pd.isnull(value):82 return na_value83 elif type(value).__module__ == np.__name__:84 return value.item()85 else:86 return value87 def _create_annotation(self):88 result = {"version": SCHEMA_VERSION_LATEST, "pairs": []}89 # transform multiindex into frame90 df_pairs = self.pairs.to_frame()91 if self.df_b is None: # dedup92 df_b = self.df_a93 dataset_b_name = self.dataset_a_name94 else: # link95 df_b = self.df_b96 dataset_b_name = self.dataset_b_name97 columns_a = list(self.df_a)98 columns_b = list(df_b)99 for index, pair in df_pairs.iterrows():100 result_record = {101 'fields': [],102 "identifiers": {103 "a": {104 "dataset": self._cast_value(self.dataset_a_name),105 "record": self._cast_value(pair[0])106 },107 "b": {108 "dataset": self._cast_value(dataset_b_name),109 "record": self._cast_value(pair[1])110 }111 },112 }113 # get the full data for this record114 for col in columns_a:115 result_record_field_a = {116 "name": self._cast_value(col),117 "value": self._get_value(self.df_a, pair[0], col),118 "type": "String"119 }120 result_record_field_b = {121 "name": self._cast_value(col),122 "value": self._get_value(df_b, pair[1], col),123 "type": "String"124 }125 result_record_field = {126 "a": self._cast_value(result_record_field_a),127 "b": self._cast_value(result_record_field_b),128 "similarity": self._cast_value(None)129 }130 result_record['fields'].append(result_record_field)131 # append the result to a file132 result['pairs'].append(result_record)133 return result134 def to_file(self, fp):135 """Write annotation object to file.136 Parameters137 ----------138 fp: str139 The path to store the annotation file.140 """141 with open(str(fp), "w") as f:142 json.dump(self._create_annotation(), f, indent=2)...
config_param.py
Source:config_param.py
...26 else:27 raise28 else:29 if self.multi:30 value = [self._cast_value(v) for v in value]31 else:32 value = self._cast_value(value[0])33 return value34 def _cast_value(self, value):35 if self.type is not None:36 try:37 value = self.type(value)38 except ValueError:39 raise ParameterTypeError(self.name, self.type, type(value))40 if self.options is not None and value not in self.options:41 raise ParameterValueError(self.name, self.options, value)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!