James McCool
commited on
Commit
·
e887235
1
Parent(s):
9e77e56
Refactor portfolio file loading to streamline assignment of DataFrames. The load_file function now returns both export and portfolio DataFrames in a single call, improving code clarity and efficiency.
Browse files- app.py +1 -3
- global_func/load_file.py +12 -9
app.py
CHANGED
|
@@ -603,9 +603,7 @@ if selected_tab == 'Data Load':
|
|
| 603 |
if st.session_state['portfolio_loaded']:
|
| 604 |
if upload_toggle == 'Paydirt DB':
|
| 605 |
portfolio_file = st.session_state['db_portfolio_file']
|
| 606 |
-
st.session_state['export_portfolio'] = portfolio_file
|
| 607 |
-
st.session_state['portfolio'] = portfolio_file
|
| 608 |
-
|
| 609 |
st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
|
| 610 |
st.session_state['export_portfolio'] = st.session_state['export_portfolio'].reset_index(drop=True)
|
| 611 |
|
|
|
|
| 603 |
if st.session_state['portfolio_loaded']:
|
| 604 |
if upload_toggle == 'Paydirt DB':
|
| 605 |
portfolio_file = st.session_state['db_portfolio_file']
|
| 606 |
+
st.session_state['export_portfolio'], st.session_state['portfolio'] = load_file(portfolio_file, site_var, type_var, sport_var, 'portfolio')
|
|
|
|
|
|
|
| 607 |
st.session_state['export_portfolio'] = st.session_state['export_portfolio'].dropna(how='all')
|
| 608 |
st.session_state['export_portfolio'] = st.session_state['export_portfolio'].reset_index(drop=True)
|
| 609 |
|
global_func/load_file.py
CHANGED
|
@@ -90,15 +90,18 @@ sport_headers = {
|
|
| 90 |
def load_file(upload, site_var, type_var, sport_var, upload_type):
|
| 91 |
if upload is not None:
|
| 92 |
try:
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
for col in df.columns:
|
| 104 |
if "Unnamed" in col:
|
|
|
|
| 90 |
def load_file(upload, site_var, type_var, sport_var, upload_type):
|
| 91 |
if upload is not None:
|
| 92 |
try:
|
| 93 |
+
try:
|
| 94 |
+
clean_name = re.sub(r' \(\d+\)', '', upload.name)
|
| 95 |
+
|
| 96 |
+
if clean_name.endswith('.csv'):
|
| 97 |
+
df = pd.read_csv(upload)
|
| 98 |
+
elif clean_name.endswith(('.xls', '.xlsx')):
|
| 99 |
+
df = pd.read_excel(upload)
|
| 100 |
+
else:
|
| 101 |
+
st.error('Please upload either a CSV or Excel file')
|
| 102 |
+
return None, None
|
| 103 |
+
except:
|
| 104 |
+
df = upload
|
| 105 |
|
| 106 |
for col in df.columns:
|
| 107 |
if "Unnamed" in col:
|