From 76a5dc8edf1a96368fdc0c5c421076709c248c61 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 30 Apr 2024 15:13:39 -0700 Subject: [PATCH] Remove hardcoding from `select_from_results.py` --- src/python/select_from_results.py | 83 ++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/src/python/select_from_results.py b/src/python/select_from_results.py index 3f048b4c76..2f608fcddb 100755 --- a/src/python/select_from_results.py +++ b/src/python/select_from_results.py @@ -1,48 +1,73 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -"""Output a subset of the results that match a hard-coded condition, to a hard-coded file. +"""Output a subset of the results, to standard out. +The arguments are a query and a list of columns. +The query is executed (to select rows), then columns are output that include: + * idx + * all the columns that appear in the query + * any additional columns specified on the command line. -To change the condition or file, edit this script. +The query is an expression using dataframe variables. +Here are examples: + (gitmerge_ort == "Merge_failed") and (spork != "Merge_failed") + (gitmerge_ort == "Merge_failed") and (spork == "Merge_failed") """ +import argparse +from os import system import pandas as pd +import re +import tempfile -df = pd.read_csv("../../results/combined/result.csv", index_col="idx") -# print(df.iloc[3]) -# print(df.iloc[3].gitmerge_ort_imports_ignorespace) -# print(df.iloc[3].gitmerge_ort_ignorespace) -# print( -# df.iloc[3].gitmerge_ort_imports_ignorespace == df.iloc[3].gitmerge_ort_ignorespace -# ) +def columns_in_query(query): + """Returns all the identifiers used in the query.""" + result = re.findall(r"""(?