Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@mutate changes other column type #305

Open
stej opened this issue May 12, 2020 · 0 comments
Open

@mutate changes other column type #305

stej opened this issue May 12, 2020 · 0 comments

Comments

@stej
Copy link

stej commented May 12, 2020

Repost from https://discourse.julialang.org/t/query-mutate-changes-other-column-type/39292 as it looks like a bug.

This is my smallest code with repro:

contents = """
"5674012","aa66aa66"
"5674012","b036aa66,b036aa67,b036aa68"
""";

batches = CSV.File(IOBuffer(contents); header = ["X1", "Splits"], delim = ',') |> DataFrame;

emptyStringArray = Array{SubString{String},1}()
batchesAny = batches |> 
            @mutate(Splits = length(_.Splits) > 0 ? split(_.Splits, ',') : emptyStringArray) |> DataFrame
batchesString = batches |> 
            @mutate(Splits = length(_.Splits) > 0 ? split(_.Splits, ',') : Array{SubString{String},1}()) |> DataFrame

The output is like this:

julia> batchesAny
2×2 DataFrame
│ Row │ X1      │ Splits                               │
│     │ Any     │ Any                                  │
├─────┼─────────┼──────────────────────────────────────┤
│ 1   │ 5674012 │ ["aa66aa66"]                         │
│ 2   │ 5674012 │ ["b036aa66", "b036aa67", "b036aa68"] │

julia> batchesString
2×2 DataFrame
│ Row │ X1      │ Splits                               │
│     │ Int64   │ Array{SubString{String},1}           │
├─────┼─────────┼──────────────────────────────────────┤
│ 1   │ 5674012 │ ["aa66aa66"]                         │
│ 2   │ 5674012 │ ["b036aa66", "b036aa67", "b036aa68"] │

What I don’t understand:

  1. :Splits column type differs - Any vs. Array{SubString{String},1}. (I just wanted to save memory so I stored the value (that can be repeated) to emptyStringArray.)

  2. Even if I understand that I made something bad to column :Splits, I think X1's type shouldn't be changed to Any in batchesAny.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant