def transform_array(array, force_list=False):
 try:
  dt2001 = np.datetime64('2001')
  legacy_datetime64 = (dt2001.astype('int64') == dt2001.astype('datetime64[ms]').astype('int64'))
 except AttributeError as e:
  if (e.args == ("'module' object has no attribute 'datetime64'",)):
   import sys
   if ('PyPy' in sys.version):
    legacy_datetime64 = False
    pass
   else:
    raise e
  else:
   raise e
 if (array.dtype.kind == 'M'):
  if legacy_datetime64:
   if (array.dtype == np.dtype('datetime64[ns]')):
    array = (array.astype('int64') / (10 ** 6.0))
  else:
   array = (array.astype('datetime64[us]').astype('int64') / 1000.0)
 elif (array.dtype.kind == 'm'):
  array = (array.astype('timedelta64[us]').astype('int64') / 1000.0)
 return serialize_array(array, force_list)

def transform_array ( array , force_list = False ) : try : dt2001 = np . datetime64 ( '2001' ) legacy_datetime64 = ( dt2001 . astype ( 'int64' ) == dt2001 . astype ( 'datetime64[ms]' ) . astype ( 'int64' ) ) except AttributeError as e : if ( e . args == ( "'module' object has no attribute 'datetime64'" , ) ) : import sys if ( 'PyPy' in sys . version ) : legacy_datetime64 = False pass else : raise e else : raise e if ( array . dtype . kind == 'M' ) : if legacy_datetime64 : if ( array . dtype == np . dtype ( 'datetime64[ns]' ) ) : array = ( array . astype ( 'int64' ) / ( 10 ** 6.0 ) ) else : array = ( array . astype ( 'datetime64[us]' ) . astype ( 'int64' ) / 1000.0 ) elif ( array . dtype . kind == 'm' ) : array = ( array . astype ( 'timedelta64[us]' ) . astype ( 'int64' ) / 1000.0 ) return serialize_array ( array , force_list )
transform a numpy arrays into serialized format converts un-serializable dtypes and returns json serializable format args: array : a numpy array to be transformed force_list : whether to only output to standard lists this function can encode some dtypes using a binary encoding .