Skip to content

Commit

Permalink
match -> elif
Browse files Browse the repository at this point in the history
  • Loading branch information
Dainius Kirsnauskas committed May 29, 2024
1 parent a095084 commit e9e2177
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions GUI/back-end/data_collection/refactoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ def set_lovd_dtypes(df_dict):
for column in frame.columns:
if column not in LOVD_TABLES_DATA_TYPES[table_name]:
raise ValueError(f"Column {column} is undefined in LOVD_TABLES_DATA_TYPES")

match LOVD_TABLES_DATA_TYPES[table_name][column]:
case "Date":
frame[column] = pd.to_datetime(frame[column], errors='coerce')
case "Boolean":
frame[column] = frame[column].map({"0": False, "1": True})
case "String":
frame[column] = frame[column].astype('string')
case "Integer":
frame[column] = pd.to_numeric(frame[column]).astype('Int64')
case "Double":
frame[column] = pd.to_numeric(frame[column]).astype('float')
case _:
raise ValueError(f"Undefined data type: "
f"{LOVD_TABLES_DATA_TYPES[table_name][column]}")
var = LOVD_TABLES_DATA_TYPES[table_name][column]
if var == "Date":
frame[column] = pd.to_datetime(frame[column], errors='coerce')
elif var == "Boolean":
frame[column] = frame[column].map({"0": False, "1": True})
elif var == "String":
frame[column] = frame[column].astype('string')
elif var == "Integer":
frame[column] = pd.to_numeric(frame[column]).astype('Int64')
elif var == "Double":
frame[column] = pd.to_numeric(frame[column]).astype('float')
else:
raise ValueError(f"Undefined data type: "
f"{LOVD_TABLES_DATA_TYPES[table_name][column]}")


def parse_lovd(path=LOVD_PATH + '/lovd_data.txt'):
Expand Down

0 comments on commit e9e2177

Please sign in to comment.