-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (44 loc) · 1.63 KB
/
main.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
52
53
# import the dependencies
import numpy as np
import pandas as pd
import typer
from pandas import DataFrame
# import the benchmark graph module
from visu import plot
# define main function in a style of the Controller pattern
# expects two CLI arguments: path to the .csv file and a name of the column in the file
def main(file: str, column: str):
# read .csv file into a Pandas DataFrame
df = read_file(file)
# check that the given column exists and its datatype is integer
check_col(df, column)
# display the benchmark for the given data
plot(df, column)
# reads file from the given path into a dataframe
def read_file(file: str):
try:
df = pd.read_csv(file)
return df
# catch any errors during reading the file
except:
# let user know that there is a mistake in the path
typer.secho(
"Incorrect file path or name", fg=typer.colors.RED # displays the message in red
)
raise typer.Exit()
# checks that the given column exists in the dataframe
def check_col(df: DataFrame, column: str):
# let user know that the given column does not exist
if column not in df.columns:
typer.secho(
"A column with the given name does not exist", fg=typer.colors.RED # displays the message in red
)
raise typer.Exit()
# let user know that the given column's data type is not integer
elif df.dtypes[column] != np.int64:
typer.secho(
"The type of the column should be an integer", fg=typer.colors.RED # displays the message in red
)
raise typer.Exit()
if __name__ == "__main__":
typer.run(main)