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

**URL:** <https://discourse.julialang.org/t/updating-old-julia-code-cant-get-past-argumenterror-invalid-index/59894>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 23, 2021, 7:28pm UTC](https://discourse.julialang.org/t/updating-old-julia-code-cant-get-past-argumenterror-invalid-index/59894 "2021-04-23T19:28:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kashjew](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@Kashjew](https://discourse.julialang.org/u/Kashjew)\
**Post date:** [April 23, 2021, 7:28pm UTC](https://discourse.julialang.org/t/updating-old-julia-code-cant-get-past-argumenterror-invalid-index/59894/1 "2021-04-23T19:28:09Z")

</div>

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).](https://github.com/zlisto/Daily-Fantasy-Baseball-Contests-in-DraftKings))

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:

 ![Invalidindex](https://global.discourse-cdn.com/julialang/original/3X/1/0/101733dfffdf0882301312616c65bfb3c1353963.png)

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);  
else  
order\_clean = 0;  
end  
else  
order\_clean=0;  
end  
Order\_clean = [Order\_clean;order\_clean];  
end  
return Order\_clean;  
end

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)

---

<div class="post-metadata">

**Author:** ![Kashjew](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@Kashjew](https://discourse.julialang.org/u/Kashjew)\
**Post date:** [April 23, 2021, 7:33pm UTC](https://discourse.julialang.org/t/updating-old-julia-code-cant-get-past-argumenterror-invalid-index/59894/2 "2021-04-23T19:33:33Z")

</div>

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

 ![badcode](https://global.discourse-cdn.com/julialang/original/3X/c/a/ca6bcb95b1fdac0fd7de5458767c9dafe5029cc5.png)

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 23, 2021, 7:40pm UTC](https://discourse.julialang.org/t/updating-old-julia-code-cant-get-past-argumenterror-invalid-index/59894/3 "2021-04-23T19:40:34Z")

</div>

Welcome!

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: [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![Kashjew](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@Kashjew](https://discourse.julialang.org/u/Kashjew)\
**Post date:** [April 23, 2021, 7:45pm UTC](https://discourse.julialang.org/t/updating-old-julia-code-cant-get-past-argumenterror-invalid-index/59894/4 "2021-04-23T19:45:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 23, 2021, 7:53pm UTC](https://discourse.julialang.org/t/updating-old-julia-code-cant-get-past-argumenterror-invalid-index/59894/5 "2021-04-23T19:53:11Z")

</div>

Yeah, there’s an easy way to post formatted code described here: [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757) but the key is to first do the work to find the _minimal_ set of code that reproduces the problem you want to solve.

---

<div class="post-metadata">

**Author:** ![Kashjew](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@Kashjew](https://discourse.julialang.org/u/Kashjew)\
**Post date:** [April 23, 2021, 8:02pm UTC](https://discourse.julialang.org/t/updating-old-julia-code-cant-get-past-argumenterror-invalid-index/59894/6 "2021-04-23T20:02:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kashjew](https://avatars.discourse-cdn.com/v4/letter/k/90db22/32.png) [@Kashjew](https://discourse.julialang.org/u/Kashjew)\
**Post date:** [April 23, 2021, 8:43pm UTC](https://discourse.julialang.org/t/updating-old-julia-code-cant-get-past-argumenterror-invalid-index/59894/7 "2021-04-23T20:43:22Z")

</div>

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

 ![error](https://global.discourse-cdn.com/julialang/original/3X/0/c/0c189b0716f98faa74f97199e1f757ad4400d776.png)  
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.

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [April 25, 2021, 4:33am UTC](https://discourse.julialang.org/t/updating-old-julia-code-cant-get-past-argumenterror-invalid-index/59894/8 "2021-04-25T04:33:48Z")

</div>

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.
