-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.py
executable file
·51 lines (41 loc) · 1.59 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import argparse
import fastexcel
def get_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("file")
parser.add_argument("-c", "--column", type=str, nargs="+", help="the columns to use")
parser.add_argument(
"--eager", action="store_true", help="wether the sheet should be loaded eagerly"
)
parser.add_argument(
"-i", "--iterations", type=int, help="the number of iterations to do", default=1
)
parser.add_argument("-t", "--table", type=str, help="the name of the table to load")
parser.add_argument(
"--print-tables", action="store_true", help="whether to print the tables in the file"
)
return parser.parse_args()
def main():
args = get_args()
excel_file = fastexcel.read_excel(args.file)
use_columns = args.column or None
if args.print_tables:
table_names = excel_file.table_names()
if len(table_names) > 0:
print(f"Available tables are {', '.join(table_names)}")
else:
print("No tables found")
for _ in range(args.iterations):
if args.table:
tbl = excel_file.load_table(args.table)
print(f"Found table {args.table}:")
print(tbl.to_polars())
else:
for sheet_name in excel_file.sheet_names:
if args.eager:
excel_file.load_sheet_eager(sheet_name, use_columns=use_columns)
else:
excel_file.load_sheet(sheet_name, use_columns=use_columns).to_arrow()
if __name__ == "__main__":
main()