Example #1
0
def compare_functions(r_func_name, pd_func_name):
    r_func = r_functions.get_r_function(r_source_file, r_func_name)
    pd_func = pd_functions.get_pd_functions(pd_source_file,
                                            as_dict=True)[pd_func_name]
    generated_args = get_generated_args(r_func, 100)
    r_results = r_functions.execute_R_function_on_args(r_func, generated_args)
    r_executed = {
        "name": r_func_name,
        "body": r_functions.get_function_body(r_func),
        "inputKey": "DF-KEY",
        "outputs": r_results
    }
    pd_results = pd_functions.execute_pd_function_on_args(
        pd_func, generated_args)
    pd_executed = {
        "name": pd_func_name,
        "body": helper.get_func_body(pd_func),
        "inputKey": "DF-KEY",
        "outputs": pd_results
    }
    r_func = Function(name=r_func_name,
                      input_key=r_executed["inputKey"],
                      outputs=Outputs(r_executed["outputs"]),
                      body=test_clustering.get_body(r_executed),
                      source=r_source_file)
    pd_func = Function(name=pd_func_name,
                       input_key=pd_executed["inputKey"],
                       outputs=Outputs(pd_executed["outputs"]),
                       body=test_clustering.get_body(pd_executed),
                       source=pd_source_file)
    print(test_clustering.execution_similarity(r_func, pd_func))
Example #2
0
def create_temp_function(variable, body):
  headers = "\n".join(['library("%s")' % header for header in R_SUPPORTED_LIBRARIES])
  func_name = helper.generate_function_name()
  func_source = """
%s <- function (%s) {
  %s
}
  """ % (func_name, variable, body)
  file_source = "\n\n".join([headers, func_source, ""])
  cache.write_file(TEMP_FUNC_PATH, file_source.encode('utf-8'))
  r_func = functions.get_r_function(TEMP_FUNC_PATH, func_name)
  return r_func
Example #3
0
def delta(r_func_name, pd_func_name):
    r_func = r_functions.get_r_function(r_source_file, r_func_name)
    pd_func = pd_functions.get_pd_functions(pd_source_file,
                                            as_dict=True)[pd_func_name]
    generated_args = get_generated_args(r_func, 1)
    print(generated_args[0])
    r_result = r_functions.execute_R_function_on_args(r_func,
                                                      generated_args)[0]
    pd_result = pd_functions.execute_pd_function_on_args(
        pd_func, generated_args)[0]
    difference = dataframer.difference(r_result['return'], pd_result['return'])
    print(difference)
Example #4
0
def get_find_assign():
  global _FIND_ASSIGN
  if not _FIND_ASSIGN:
    _FIND_ASSIGN = functions.get_r_function(R_PARSER_PATH, "find_assign")
  return _FIND_ASSIGN
Example #5
0
def get_find_var_func():
  global _FIND_VAR_FUNC
  if not _FIND_VAR_FUNC:
    _FIND_VAR_FUNC = functions.get_r_function(R_PARSER_PATH, "find_vars")
  return _FIND_VAR_FUNC