Updating Old Julia Code - Cant get past ArgumentError: Invalid Index

Hello. I am new to Julia and I have been updating the code from the Picking Winner’s Paper (GitHub - zlisto/Daily-Fantasy-Baseball-Contests-in-DraftKings: This is the code for constructing a portfolio of lineups for DraftKings baseball contests with a top heavy payoff structure. This code is based on the paper Picking Winners Using Integer Programming by David Hunter, Juan Pablo Vielma, and Tauhid Zaman (https://arxiv.org/abs/1604.01455).)

I have been able to figure out how to update a fair amount of this old Julia code, however I am stuck on this error that I get when running the code:

I believe that the error has to do with this portion of the code, but again I am new so I could be way off:
function clean_order(Order) #cleans up the batting order so that it is a number
Order_clean =;
for order in Order
if ~(typeof(order)==DataArrays.NAtype)
if isa(parse(order), Number)
order_clean = parse(order);
order_clean = 0;
Order_clean = [Order_clean;order_clean];
return Order_clean;

Please see the Zlisto GitHub above for the full code. I have updated many things in my code but its 98% the same ( things I updated include: getting rid of {}, -defVar->-Variable, -objective, -constraint, fixed the old way to read CSV files)

sorry it wont let me add two pictures in my first post…


I think you may be wrong about the location of the error. The error that you showed in your first post refers to the call to CSV.File within create_lineups, which doesn’t seem to be the part of the code that you posted. I also looked at the original code in the repo, but it looks like you must have changed that part of the code as well.

I’m assuming that you found that the readtable function was removed from DataFrames a while ago and probably replaced it with a call to some function in CSV.jl, but I’m really just guessing because I can’t see what you’ve done.

What I would suggest is:

  • Reduce the problem to the minimal function which fails. That means figuring out which function is failing and what its expected inputs are.
  • Post that minimal failing example here, using the ``` backticks to format it (rather than pasting a screenshot). There’s lots of good info about making it easier to help you here: PSA: make it easier to help you
1 Like

I would like to post my changes, however, I don’t have a good way to post it. Is there a preferred method to posting one’s code on this forum?

Yeah, there’s an easy way to post formatted code described here: PSA: make it easier to help you but the key is to first do the work to find the minimal set of code that reproduces the problem you want to solve.

Thank you for being patient with me. I completely missed that you had already mentioned that PSA, haha. I am attempting to do what you are suggesting and isolate the error, by taking small portions of the code and running it, still yet to find it.

1 Like

I believe I have isolated the error down to this section of code as shown here:

In running many sections of all this old code I think I have uncovered other errors that perhaps might be contributing to this error.

One example is m = Model(solver=GurobiSolver(OutputFlag=0)) this code comes up with a long error explaining that Gurobi went through a major update and to revert to an old version

there were many UndDefVar errors, but I believe those occurred because I was running smaller portions of code.

The error you are showing in this picture is that in the original version, the variable player is a DataFrame created by the read_player_data function. In your version, player is a CSV.File. A CSV.File cannot be indexed like [1,:Batting_Order_Confirmed_]. You need to correct your version so that players is a DataFrame again. This will also fix the problem you had in yhe first picture.

Another good advice to update old julia code is to go version by version. By the date of the paper, it looks like it would be a good Idea to start running it with Julia v0.7. Julia v0.7 has especially crafted to make it easier to people to upgrade code from v0.6 to v1.0, where Julia became stable. Using v0.7 you will get useful messages about syntax and functions that were deprecated and it will suggest how to update them.

I saw that you were referred to the PSA, make it easier to help you. Please see number one: Don’t post your code as a screenshot; it is difficult to read and impossible to copy-paste.. Usually if you paste a complete code that we can copy and paste to get your error (instead of a picture), it will be more likely that you will receive a helpful answer.