James McCool
commited on
Commit
·
8781f64
1
Parent(s):
e887235
Enhance load_file function to check if the upload is already a DataFrame, improving handling of file uploads. This change simplifies the logic for processing uploaded data and ensures compatibility with existing DataFrame objects.
Browse files- global_func/load_file.py +5 -3
global_func/load_file.py
CHANGED
|
@@ -90,7 +90,11 @@ 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 |
clean_name = re.sub(r' \(\d+\)', '', upload.name)
|
| 95 |
|
| 96 |
if clean_name.endswith('.csv'):
|
|
@@ -100,8 +104,6 @@ def load_file(upload, site_var, type_var, sport_var, upload_type):
|
|
| 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:
|
|
|
|
| 90 |
def load_file(upload, site_var, type_var, sport_var, upload_type):
|
| 91 |
if upload is not None:
|
| 92 |
try:
|
| 93 |
+
# Check if upload is already a DataFrame (from database)
|
| 94 |
+
if isinstance(upload, pd.DataFrame):
|
| 95 |
+
df = upload.copy()
|
| 96 |
+
else:
|
| 97 |
+
# Handle file upload object
|
| 98 |
clean_name = re.sub(r' \(\d+\)', '', upload.name)
|
| 99 |
|
| 100 |
if clean_name.endswith('.csv'):
|
|
|
|
| 104 |
else:
|
| 105 |
st.error('Please upload either a CSV or Excel file')
|
| 106 |
return None, None
|
|
|
|
|
|
|
| 107 |
|
| 108 |
for col in df.columns:
|
| 109 |
if "Unnamed" in col:
|