def _convert_multi_part_output(self, content, content_type): multipart_data = decoder.MultipartDecoder(content=content , content_type=content_type) ret = {} for part in multipart_data.parts: # typically something like: b'form-data; name="input1"' name_with_form_data = str(part.headers[b'Content-Disposition']) name_str = re.sub(r'([";\\\']|name=|form-data|b\\)', '', name_with_form_data).replace('b ', '') if self.output_type.upper() == 'NUMPY': ret[name_str] = Client._convert_binary_to_numpy(part.content) elif self.output_type.upper() == 'ARROW': reader = RecordBatchFileReader(part.content) ret[name_str] = reader.read_pandas() elif self.output_type.upper() == 'JSON': return json.load(part.content) elif self.output_type.upper() == 'ND4J': raise NotImplementedError('Nd4j not implemented yet.') else: ret[name_str] = part.content return ret
def _parse_response(self, content, content_type): try: if self.output_names is None or len(self.output_names) < 2: bytes_content = io.BytesIO(content) bytes_content.seek(0) if self.return_output_type.upper() == 'NUMPY': return np.load(bytes_content) elif self.return_output_type.upper() == 'ARROW': reader = RecordBatchFileReader(bytes_content) return reader.read_pandas() elif self.return_output_type.upper() == 'JSON': return json.load(bytes_content) elif self.return_output_type.upper() == 'ND4J': raise NotImplementedError('Nd4j not implemented yet.') elif self.return_output_type.upper() == 'RAW': return content else: return self._convert_multi_part_output(content, content_type) except Exception as e: print(e) return None
def _parse_response(self, content, content_type): try: if self.output_names is None or len(self.output_names) < 2: bytes_content = io.BytesIO(content) bytes_content.seek(0) if self.convert_to_format.upper() == "NUMPY": return np.load(bytes_content) elif self.convert_to_format.upper() == "ARROW": reader = RecordBatchFileReader(bytes_content) return reader.read_pandas() elif self.convert_to_format.upper() == "JSON": return json.load(bytes_content) elif self.convert_to_format.upper() == "IMAGE": raise NotImplementedError("Image not implemented yet.") elif self.convert_to_format.upper() == "RAW": return content else: return self._convert_multi_part_output(content, content_type) except Exception as e: logging.info(e) return None