Gmousse/dataframe-js

[QUESTION] How to set rows?

Closed this issue · 1 comments

Ask your question
After following the API and a previously opened issue I am unable to set a row with new data.

Additional context
Wrapper class:

export default class DF {
  constructor(data, columns) {
    this.dataFrame = new DataFrame(data, columns);
  }

  setRow = (index, key, val) => {
    console.log('index ', index, 'key ', key, 'val ', val);
    this.dataFrame.setRow(index, row => row.set(key, val));
    console.log('updated df ', this.dataFrame.toCollection())
  };
}

The method setRow lives inside of a wrapper class that I have where this.dataFrame is my DataFrame. When I call setRow with for example index 0 I am able to find the correct row and can see that the row has the fields that I am trying to update, I then update those fields and return the new row(with updated values), after I return the updated row I call this.DataFrame.toCollection() and check index 0 of the collection only to find my old data.

Am I miss using the API in some way?

Update: Because DataFrames are immutable you have to set this.dataFrame to the result of setRow and then your new DataFrame will contain your updated value