parameters: (data, se)
return_statement: return out
docstring: Convert data according to the schema encoding
docstring_summary: Convert data according to the schema encoding
docstring_tokens: Convert data according to the schema encoding
function: def convert(data, se):
      """Convert data according to the schema encoding"""
      dtype = data.dtype
      type = se.type
      converted_type = se.converted_type
      if dtype.name in typemap:
          if type in revmap:
              out = data.values.astype(revmap[type], copy=False)
          elif type == parquet_thrift.Type.BOOLEAN:
              padded = np.lib.pad(data.values, (0, 8 - (len(data) % 8)),
                                  'constant', constant_values=(0, 0))
              out = np.packbits(padded.reshape(-1, 8)[:, ::-1].ravel())
          elif dtype.name in typemap:
              out = data.values
      elif "S" in str(dtype)[:2] or "U" in str(dtype)[:2]:
          out = data.values
      elif dtype == "O":
          try:
              if converted_type == parquet_thrift.ConvertedType.UTF8:
                  out = array_encode_utf8(data)
              elif converted_type is None:
                  if type in revmap:
                      out = data.values.astype(revmap[type], copy=False)
                  elif type == parquet_thrift.Type.BOOLEAN:
                      padded = np.lib.pad(data.values, (0, 8 - (len(data) % 8)),
                                          'constant', constant_values=(0, 0))
                      out = np.packbits(padded.reshape(-1, 8)[:, ::-1].ravel())
                  else:
                      out = data.values
              elif converted_type == parquet_thrift.ConvertedType.JSON:
                  out = np.array([json.dumps(x).encode('utf8') for x in data],
                                 dtype="O")
              elif converted_type == parquet_thrift.ConvertedType.BSON:
                  out = data.map(tobson).values
              if type == parquet_thrift.Type.FIXED_LEN_BYTE_ARRAY:
                  out = out.astype('S%i' % se.type_length)
          except Exception as e:
              ct = parquet_thrift.ConvertedType._VALUES_TO_NAMES[
                  converted_type] if converted_type is not None else None
              raise ValueError('Error converting column "%s" to bytes using '
                               'encoding %s. Original error: '
                               '%s' % (data.name, ct, e))
      elif converted_type == parquet_thrift.ConvertedType.TIMESTAMP_MICROS:
          out = np.empty(len(data), 'int64')
          time_shift(data.values.view('int64'), out)
      elif converted_type == parquet_thrift.ConvertedType.TIME_MICROS:
          out = np.empty(len(data), 'int64')
          time_shift(data.values.view('int64'), out)
      elif type == parquet_thrift.Type.INT96 and dtype.kind == 'M':
          ns_per_day = (24 * 3600 * 1000000000)
          day = data.values.view('int64') // ns_per_day + 2440588
          ns = (data.values.view('int64') % ns_per_day)# - ns_per_day // 2
          out = np.empty(len(data), dtype=[('ns', 'i8'), ('day', 'i4')])
          out['ns'] = ns
          out['day'] = day
      else:
          raise ValueError("Don't know how to convert data type: %s" % dtype)
      return out
function_tokens: def convert ( data , se ) : dtype = data . dtype type = se . type converted_type = se . converted_type if dtype . name in typemap : if type in revmap : out = data . values . astype ( revmap [ type ] , copy = False ) elif type == parquet_thrift . Type . BOOLEAN : padded = np . lib . pad ( data . values , ( 0 , 8 - ( len ( data ) % 8 ) ) , 'constant' , constant_values = ( 0 , 0 ) ) out = np . packbits ( padded . reshape ( - 1 , 8 ) [ : , : : - 1 ] . ravel ( ) ) elif dtype . name in typemap : out = data . values elif "S" in str ( dtype ) [ : 2 ] or "U" in str ( dtype ) [ : 2 ] : out = data . values elif dtype == "O" : try : if converted_type == parquet_thrift . ConvertedType . UTF8 : out = array_encode_utf8 ( data ) elif converted_type is None : if type in revmap : out = data . values . astype ( revmap [ type ] , copy = False ) elif type == parquet_thrift . Type . BOOLEAN : padded = np . lib . pad ( data . values , ( 0 , 8 - ( len ( data ) % 8 ) ) , 'constant' , constant_values = ( 0 , 0 ) ) out = np . packbits ( padded . reshape ( - 1 , 8 ) [ : , : : - 1 ] . ravel ( ) ) else : out = data . values elif converted_type == parquet_thrift . ConvertedType . JSON : out = np . array ( [ json . dumps ( x ) . encode ( 'utf8' ) for x in data ] , dtype = "O" ) elif converted_type == parquet_thrift . ConvertedType . BSON : out = data . map ( tobson ) . values if type == parquet_thrift . Type . FIXED_LEN_BYTE_ARRAY : out = out . astype ( 'S%i' % se . type_length ) except Exception as e : ct = parquet_thrift . ConvertedType . _VALUES_TO_NAMES [ converted_type ] if converted_type is not None else None raise ValueError ( 'Error converting column "%s" to bytes using ' 'encoding %s. Original error: ' '%s' % ( data . name , ct , e ) ) elif converted_type == parquet_thrift . ConvertedType . TIMESTAMP_MICROS : out = np . empty ( len ( data ) , 'int64' ) time_shift ( data . values . view ( 'int64' ) , out ) elif converted_type == parquet_thrift . ConvertedType . TIME_MICROS : out = np . empty ( len ( data ) , 'int64' ) time_shift ( data . values . view ( 'int64' ) , out ) elif type == parquet_thrift . Type . INT96 and dtype . kind == 'M' : ns_per_day = ( 24 * 3600 * 1000000000 ) day = data . values . view ( 'int64' ) // ns_per_day + 2440588 ns = ( data . values . view ( 'int64' ) % ns_per_day ) # - ns_per_day // 2 out = np . empty ( len ( data ) , dtype = [ ( 'ns' , 'i8' ) , ( 'day' , 'i4' ) ] ) out [ 'ns' ] = ns out [ 'day' ] = day else : raise ValueError ( "Don't know how to convert data type: %s" % dtype ) return out