Issue inserting row in TabularData's DataFrame

I'm fairly new to Swift programming so I might be overlooking something, but I'm puzzled why the following code doesn't properly insert a row in a DataFrame. The goal is to move a row at a given index to a new index. I would normally:

  1. Copy the row that I want to move
  2. Remove the row from the original dataset
  3. Insert the copy to the new position

The CSV I'm using is from Wikipedia:

Year,Make,Model,Description,Price
1997,Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very Large""","",5000.00
1996,Jeep,Grand Cherokee,"MUST SELL! air, moon roof, loaded",4799.00

My code (Swift playground):

import Foundation
import TabularData

let fileUrl = Bundle.main.url(forResource: "data", withExtension: "csv")
let options = CSVReadingOptions(hasHeaderRow: true, delimiter: ",")
var dataFrame = try! DataFrame(contentsOfCSVFile: fileUrl!, options: options)

print("Original data")
print(dataFrame)

let rowToMove: Int = 2
let row = dataFrame.rows[rowToMove]
print("Row to move")
print(row)

dataFrame.removeRow(at: rowToMove)
print("After removing")
print(dataFrame)

dataFrame.insert(row: row, at: 0)
print("After inserting")
print(dataFrame)

This results in the following:

Original data
┏━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃   ┃ Year  ┃ Make     ┃ Model                                  ┃ Description                       ┃ Price    ┃
┃   ┃ <Int> ┃ <String> ┃ <String>                               ┃ <String>                          ┃ <Double> ┃
┡━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 0 │ 1,997 │ Ford     │ E350                                   │ ac, abs, moon                     │  3,000.0 │
│ 1 │ 1,999 │ Chevy    │ Venture "Extended Edition"             │                                   │  4,900.0 │
│ 2 │ 1,999 │ Chevy    │ Venture "Extended Edition, Very Large" │                                   │  5,000.0 │
│ 3 │ 1,996 │ Jeep     │ Grand Cherokee                         │ MUST SELL! air, moon roof, loaded │  4,799.0 │
└───┴───────┴──────────┴────────────────────────────────────────┴───────────────────────────────────┴──────────┘
4 rows, 5 columns

Row to move
┏━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃   ┃ Year  ┃ Make     ┃ Model                                  ┃ Description ┃ Price    ┃
┃   ┃ <Int> ┃ <String> ┃ <String>                               ┃ <String>    ┃ <Double> ┃
┡━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 2 │ 1,999 │ Chevy    │ Venture "Extended Edition, Very Large" │             │  5,000.0 │
└───┴───────┴──────────┴────────────────────────────────────────┴─────────────┴──────────┘
1 row, 5 columns

After removing
┏━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃   ┃ Year  ┃ Make     ┃ Model                      ┃ Description                       ┃ Price    ┃
┃   ┃ <Int> ┃ <String> ┃ <String>                   ┃ <String>                          ┃ <Double> ┃
┡━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 0 │ 1,997 │ Ford     │ E350                       │ ac, abs, moon                     │  3,000.0 │
│ 1 │ 1,999 │ Chevy    │ Venture "Extended Edition" │                                   │  4,900.0 │
│ 2 │ 1,996 │ Jeep     │ Grand Cherokee             │ MUST SELL! air, moon roof, loaded │  4,799.0 │
└───┴───────┴──────────┴────────────────────────────┴───────────────────────────────────┴──────────┘
3 rows, 5 columns

After inserting
┏━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃   ┃ Year  ┃ Make     ┃ Model                                  ┃ Description                       ┃ Price    ┃
┃   ┃ <Int> ┃ <String> ┃ <String>                               ┃ <String>                          ┃ <Double> ┃
┡━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 0 │ 1,999 │ Chevy    │  │                                   │  5,000.0 │
│ 1 │ 1,997 │ Ford     │ E350                                   │ ac, abs, moon                     │  3,000.0 │
│ 2 │ 1,996 │ Jeep     │ Grand Cherokee                         │ MUST SELL! air, moon roof, loaded │  4,799.0 │
│ 3 │   nil │ nil      │ nil                                    │ nil                               │      nil │
└───┴───────┴──────────┴────────────────────────────────────────┴───────────────────────────────────┴──────────┘
4 rows, 5 columns

Everything is fine up until inserting. I spot a few issues:

  1. A row gets deleted (original data row 1)
  2. A row filled with nil's is added (at index 3)
  3. the row I want to insert isn't properly inserted (notice how the 'model' text has gone).

I assume I'm missing something - does it have to do with the row copy keeping its index (2)? How can I fix this?

Replies

This looks like it may be a bug. Do you mind filling an issue with Feedback Assistant?

Sure - just done. How long do these things (roughly) take to get addressed? Just so I know if I should be looking at other technologies to achieve the same thing, or write my own implementation.

Can you share the feedback ID so that I can make sure it goes to the right place. We'll get it fixed ASAP.

I believe that would be this one: FB12519111

Thank you!