ziggycross commited on
Commit
9ac3994
1 Parent(s): 7ad6c98

Removed unsupported match/case from modules.

Browse files
Files changed (1) hide show
  1. modules.py +20 -17
modules.py CHANGED
@@ -2,6 +2,8 @@ import pandas as pd
2
 
3
  SUPPORTED_TYPES = [".csv", ".json", ".xlsx"]
4
 
 
 
5
  def load_file(file):
6
  """
7
  Takes a file given by Streamlit and loads into a DataFrame.
@@ -13,22 +15,22 @@ def load_file(file):
13
  """
14
  df = pd.DataFrame()
15
 
16
- if file is None: return df, ""
17
 
18
  filename = file.name
19
  extension = filename.split(".")[-1]
20
  metadata = (filename, extension)
21
 
 
 
 
 
 
22
  try:
23
- match extension:
24
- case "csv":
25
- df = pd.read_csv(file)
26
- case "json":
27
- df = pd.read_json(file)
28
- case "xlsx":
29
- df = pd.read_excel(file)
30
- case _:
31
- return df, metadata, f"Error: Invalid extension '{extension}'"
32
  rows, columns = df.shape
33
  return df, metadata, f"File '{filename}' loaded successfully.\nFound {rows} rows, {columns} columns."
34
  except Exception as error:
@@ -44,13 +46,14 @@ def create_file(df, extension):
44
  @param extension: The desired filetype.
45
  @return: A file container ready for download.
46
  """
47
- match extension:
48
- case "csv":
49
- return df.to_csv()
50
- case "json":
51
- return df.to_json()
52
- case "xlsx":
53
- return df.to_excel()
 
54
 
55
  def data_cleaner(df, drop_missing=False, remove_duplicates=True):
56
  """
 
2
 
3
  SUPPORTED_TYPES = [".csv", ".json", ".xlsx"]
4
 
5
+ def hello_world(): return "hello world!"
6
+
7
  def load_file(file):
8
  """
9
  Takes a file given by Streamlit and loads into a DataFrame.
 
15
  """
16
  df = pd.DataFrame()
17
 
18
+ if file is None: return df, ("", ""), ""
19
 
20
  filename = file.name
21
  extension = filename.split(".")[-1]
22
  metadata = (filename, extension)
23
 
24
+ import_functions = {
25
+ "csv": pd.read_csv,
26
+ "json": pd.read_json,
27
+ "xlsx": pd.read_excel
28
+ }
29
  try:
30
+ reader = import_functions.get(extension, None)
31
+ if reader is None:
32
+ return df, metadata, f"Error: Invalid extension '{extension}'"
33
+ df = reader(file)
 
 
 
 
 
34
  rows, columns = df.shape
35
  return df, metadata, f"File '{filename}' loaded successfully.\nFound {rows} rows, {columns} columns."
36
  except Exception as error:
 
46
  @param extension: The desired filetype.
47
  @return: A file container ready for download.
48
  """
49
+ export_functions = {
50
+ "csv": pd.DataFrame.to_csv,
51
+ "json": pd.DataFrame.to_json,
52
+ "xlsx": pd.DataFrame.to_excel
53
+ }
54
+ exporter = export_functions.get(extension, None)
55
+ if exporter is None: return None
56
+ return exporter(df)
57
 
58
  def data_cleaner(df, drop_missing=False, remove_duplicates=True):
59
  """