DavMelchi commited on
Commit
7c8002a
·
1 Parent(s): f5a37e2

Remove xlwings for hugging face

Browse files
Files changed (2) hide show
  1. apps/dump_compare.py +25 -21
  2. requirements.txt +0 -0
apps/dump_compare.py CHANGED
@@ -4,8 +4,8 @@ import tempfile
4
 
5
  import pandas as pd
6
  import streamlit as st
7
- import xlwings as xw
8
- from pyxlsb import open_workbook
9
 
10
  # === Core Logic ===
11
 
@@ -18,29 +18,33 @@ def find_header_row(df, keyword="Dist_Name"):
18
  raise ValueError(f"No row with '{keyword}' found.")
19
 
20
 
21
- def read_xlsb_with_pyxlsb(file, sheet):
22
- rows = []
23
- with open_workbook(file) as wb:
24
- with wb.get_sheet(sheet) as s:
25
- for row in s.rows():
26
- rows.append([item.v for item in row])
27
- return pd.DataFrame(rows)
 
 
 
 
 
28
 
29
 
30
  def read_sheet_fallback(file, sheet):
31
  try:
32
- return read_xlsb_with_pyxlsb(file, sheet)
33
- except Exception:
34
- try:
35
- app = xw.App(visible=False)
36
- book = app.books.open(file)
37
- sht = book.sheets[sheet]
38
- df = sht.used_range.options(pd.DataFrame, header=False, index=False).value
39
- book.close()
40
- app.quit()
41
- return df
42
- except Exception as e2:
43
- raise RuntimeError(f"xlwings failed: {e2}")
44
 
45
 
46
  def load_clean_df(file, sheet):
 
4
 
5
  import pandas as pd
6
  import streamlit as st
7
+
8
+ # import xlwings as xw
9
 
10
  # === Core Logic ===
11
 
 
18
  raise ValueError(f"No row with '{keyword}' found.")
19
 
20
 
21
+ # import xlwings as xw
22
+ # def read_sheet_fallback(file, sheet):
23
+ # try:
24
+ # app = xw.App(visible=False)
25
+ # book = app.books.open(file)
26
+ # sht = book.sheets[sheet]
27
+ # df = sht.used_range.options(pd.DataFrame, header=False, index=False).value
28
+ # book.close()
29
+ # app.quit()
30
+ # return df
31
+ # except Exception as e2:
32
+ # raise RuntimeError(f"xlwings failed: {e2}")
33
 
34
 
35
  def read_sheet_fallback(file, sheet):
36
  try:
37
+ # pandas can directly read Excel files
38
+ # sheet_name can be the sheet name (string) or sheet number (0-indexed)
39
+ df = pd.read_excel(file, sheet_name=sheet, header=None, engine="calamine")
40
+ return df
41
+ except FileNotFoundError:
42
+ raise FileNotFoundError(f"The file '{file}' was not found.")
43
+ except ValueError as e:
44
+ # This could happen if the sheet doesn't exist, or other pandas-related errors
45
+ raise ValueError(f"Error reading sheet '{sheet}' from '{file}': {e}")
46
+ except Exception as e:
47
+ raise RuntimeError(f"An unexpected error occurred: {e}")
 
48
 
49
 
50
  def load_clean_df(file, sheet):
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ