Skip to content

Commit

Permalink
Convert to string with a fixed float precision
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth-krishna committed Nov 29, 2024
1 parent 59a0eec commit aea2790
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion xl2times/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def read_csv_tables(input_dir: str) -> dict[str, DataFrame]:
result = {}
csv_files = list(Path(input_dir).glob("*.csv"))
for filename in csv_files:
result[filename.stem] = pd.read_csv(filename, dtype=str)
result[filename.stem] = pd.read_csv(filename)
return result


Expand Down Expand Up @@ -508,6 +508,8 @@ def run(args: argparse.Namespace) -> str | None:

if args.ground_truth_dir:
ground_truth = read_csv_tables(args.ground_truth_dir)
# Use the same convert_to_string transform on GT so that comparisons are fair
ground_truth = transforms.convert_to_string(config, ground_truth, model)
comparison = compare(tables, ground_truth, args.output_dir)
return comparison
else:
Expand Down
4 changes: 3 additions & 1 deletion xl2times/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2735,7 +2735,9 @@ def convert_to_string(
) -> dict[str, DataFrame]:
for key, value in tables.items():
tables[key] = value.map(
lambda x: str(int(x)) if isinstance(x, float) and x.is_integer() else str(x)
lambda x: (str(int(x)) if x.is_integer() else f"{x:.8g}")
if isinstance(x, float)
else str(x)
)
return tables

Expand Down

0 comments on commit aea2790

Please sign in to comment.