Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ def generate_lineup_files(

# Truncate all string columns to 12 characters for printing
for col in combined_df_print.columns:
if combined_df_print[col].dtype == 'object':
combined_df_print.loc[:, col] = combined_df_print[col].str[:12]
if pd.api.types.is_string_dtype(combined_df_print[col]) or combined_df_print[col].dtype == 'object':
combined_df_print.loc[:, col] = combined_df_print[col].astype(str).str[:12]

print(combined_df_print.to_string(index=False, header=False))

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "DraftKings lineup optimizer using linear programming"
readme = "README.md"
requires-python = ">=3.14"
dependencies = [
"pandas==2.3.3",
"pandas==3.0.0rc0",
"pulp==3.3.0",
"pydantic==2.12.5",
"pytest==9.0.1",
Expand Down
28 changes: 16 additions & 12 deletions tests/test_things.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from main import LineupConfig, OptimizationParams, calculate_lineups, generate_lineup_files, validate_players_data


@pytest.fixture(autouse=True)
@pytest.fixture(scope='module', autouse=True)
def generate_files():
generate_lineup_files('./tests/draftkings.csv')

Expand All @@ -19,15 +19,19 @@ def test_generate_lineup_files():


def test_generate_lineup_files_no_two_te():
# The fixture runs before this test and creates two_te.csv, so remove it first
if os.path.exists('two_te.csv'):
os.remove('two_te.csv')
try:
# The fixture runs before this test and creates two_te.csv, so remove it first
if os.path.exists('two_te.csv'):
os.remove('two_te.csv')

generate_lineup_files('./tests/draftkings.csv', allow_two_te=False)
generate_lineup_files('./tests/draftkings.csv', allow_two_te=False)

assert os.path.exists('four_wr.csv')
assert os.path.exists('three_rb.csv')
assert not os.path.exists('two_te.csv')
assert os.path.exists('four_wr.csv')
assert os.path.exists('three_rb.csv')
assert not os.path.exists('two_te.csv')
finally:
# Restore files for other tests since fixture is now module scoped
generate_lineup_files('./tests/draftkings.csv')


def test_four_wr():
Expand Down Expand Up @@ -111,7 +115,7 @@ def test_must_include_players():

# Check that Lamar Jackson appears in every lineup
for _, row in df.iterrows():
row_str = ','.join(row.astype(str))
row_str = ','.join(row.map(str))
assert 'Lamar Jackson' in row_str, "Must-include player 'Lamar Jackson' not found in lineup"
finally:
if os.path.exists(output_file + '.csv'):
Expand Down Expand Up @@ -155,7 +159,7 @@ def test_only_use_players():

# Parse the lineup to check that only specified players are used
for _, row in df.iterrows():
row_str = ','.join(row.astype(str))
row_str = ','.join(row.map(str))
# Check for some players that should NOT be in the output
assert 'Jayden Daniels' not in row_str, 'Player not in only_use list found in lineup'
assert 'Joe Burrow' not in row_str, 'Player not in only_use list found in lineup'
Expand Down Expand Up @@ -271,7 +275,7 @@ def test_exclude_players():

# Check that excluded players do not appear in any lineup
for _, row in df.iterrows():
row_str = ','.join(row.astype(str))
row_str = ','.join(row.map(str))
for excluded_player in exclude:
assert excluded_player not in row_str, f"Excluded player '{excluded_player}' found in lineup"
finally:
Expand Down Expand Up @@ -375,7 +379,7 @@ def test_unique_lineups_generated():
# Convert each row to a string and check for uniqueness
lineup_strings = set()
for _, row in df.iterrows():
lineup_str = ','.join(row.astype(str))
lineup_str = ','.join(row.map(str))
assert lineup_str not in lineup_strings, 'Duplicate lineup found'
lineup_strings.add(lineup_str)
finally:
Expand Down
45 changes: 19 additions & 26 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.