James McCool
Refactor file type checks in loading functions: update conditions in load_dk_fd_file.py, load_file.py, and load_ss_file.py to use substring checks for file extensions, improving readability and maintainability. Remove debug print statements from load_dk_fd_file.py and app.py to clean up the code.
dbc3f23
raw
history blame
999 Bytes
import streamlit as st
import numpy as np
import pandas as pd
import time
from fuzzywuzzy import process
## import global functions
from global_func.clean_player_name import clean_player_name
def load_file(upload):
if upload is not None:
try:
if '.csv' in upload.name:
df = pd.read_csv(upload)
elif any(ext in upload.name for ext in ['.xls', '.xlsx']):
df = pd.read_excel(upload)
else:
st.error('Please upload either a CSV or Excel file for lineups')
return None, None
export_df = df.copy()
for col in df.columns:
if df[col].dtype == 'object':
df[col] = df[col].apply(lambda x: clean_player_name(x) if isinstance(x, str) else x)
return export_df, df
except Exception as e:
st.error(f'Error loading file: {str(e)}')
return None
return None