# Set index! not defined for WeakRefStrings. SpringArray{String,1}

**URL:** https://discourse.julialang.org/t/set-index-not-defined-for-weakrefstrings-springarray-string-1/41379
**Category:** General Usage
**Tags:** question
**Created:** [June 14, 2020, 2:30pm UTC](https://discourse.julialang.org/t/set-index-not-defined-for-weakrefstrings-springarray-string-1/41379 "2020-06-14T14:30:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Gp\_Ubit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gp_ubit/32/15666_2.png) [@Gp\_Ubit](https://discourse.julialang.org/u/Gp_Ubit)
#### Post date: [June 14, 2020, 2:30pm UTC](https://discourse.julialang.org/t/set-index-not-defined-for-weakrefstrings-springarray-string-1/41379/1 "2020-06-14T14:30:58Z")

</div>

i wanted to create a loop on a column in my IJulia and I came up with this error. Please what can I do to retify it.

Here is my code:  
for v=1:length(col1)  
col1[v] = Dates.DateTime(col1[v], “d-u-y”)  
end

And I got this error:  
setindex! not defined for WeakRefStrings.StringArray{String,1}

Stacktrace:  
[1] error(::String, ::Type{T} where T) at .\error.jl:42  
[2] error\_if\_canonical\_setindex(::IndexLinear, ::WeakRefStrings.StringArray{String,1}, ::Int64) at .\abstractarray.jl:1081  
[3] setindex!(::WeakRefStrings.StringArray{String,1}, ::DateTime, ::Int64) at .\abstractarray.jl:1072  
[4] top-level scope at .\In[130]:2

I decided to try changing the code a little bit using:  
i in col1  
global col1[i] = Dates.DateTime(string.(col1[i]), “d-u-y”)  
end

Then I still got this error;:  
ArgumentError: invalid index: “4-Jul-2014” of type String

Stacktrace:  
[1] to\_index(::String) at .\indices.jl:297  
[2] to\_index(::WeakRefStrings.StringArray{String,1}, ::String) at .\indices.jl:274  
[3] to\_indices at .\indices.jl:325 [inlined]  
[4] to\_indices at .\indices.jl:322 [inlined]  
[5] getindex(::WeakRefStrings.StringArray{String,1}, ::String) at .\abstractarray.jl:980  
[6] top-level scope at .\In[136]:2

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [June 14, 2020, 5:54pm UTC](https://discourse.julialang.org/t/set-index-not-defined-for-weakrefstrings-springarray-string-1/41379/2 "2020-06-14T17:54:36Z")

</div>

I’m not 100% since you didn’t show how you where initialize `col1`…So I can’t test anything. But it appears that `col1` is a Vector of Strings since you are passing the value of DateTime(), however you are also trying to set `col1` to the DateTime **structure** that is being returned from the function.

So you are basically trying to change the type from `String` to `DateTime`. My guess is that is the issue. Was col1 initialize as an array of Any or as an Array of Strings?

---

<div class="post-metadata">

### Author: ![Gp\_Ubit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gp_ubit/32/15666_2.png) [@Gp\_Ubit](https://discourse.julialang.org/u/Gp_Ubit)
#### Post date: [June 14, 2020, 7:08pm UTC](https://discourse.julialang.org/t/set-index-not-defined-for-weakrefstrings-springarray-string-1/41379/3 "2020-06-14T19:08:09Z")

</div>

![NOTEBOOK-1](https://global.discourse-cdn.com/julialang/original/3X/1/1/1170de08491616146e9d725ede781af82b693cc4.png)

Here is a screenshot of the col1 initiation.

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [June 14, 2020, 7:39pm UTC](https://discourse.julialang.org/t/set-index-not-defined-for-weakrefstrings-springarray-string-1/41379/4 "2020-06-14T19:39:23Z")

</div>

Okay, so that is an array of strings, so you could do something like:

```julia
col1dt = Vector{Dates.DateTime}(undef, length(col1))
for v = 1:length(col1)
    col1dt[v] = Dates.DateTime(col1[v], "d-u-y")
end

```

Then all your DateTime objects will be in `col1dt`…

---

<div class="post-metadata">

### Author: ![Gp\_Ubit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gp_ubit/32/15666_2.png) [@Gp\_Ubit](https://discourse.julialang.org/u/Gp_Ubit)
#### Post date: [June 15, 2020, 2:34pm UTC](https://discourse.julialang.org/t/set-index-not-defined-for-weakrefstrings-springarray-string-1/41379/5 "2020-06-15T14:34:32Z")

</div>

It worked. Thank you very much
