danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

DataFrame's get accessor throws exception after column values replaced via set (using Series)

Open jm-boley opened this issue 2 years ago • 1 comments

Describe the bug Unable to access DataFrame columns with get (e.g., df['foo']) after using set to replace an existing column. Attempts to access via get throw the following exception (from the Chrome browser):

Uncaught Error: File format not supported!                                                 startup:4
    at t.e (startup:4:47)
    at new t (startup:4:47)
    at t.$getColumnData (startup:4:47)
    at t.get (startup:4:47)
    at <anonymous>:1:17

To Reproduce: In the browser interactive console:

let df = new dfd.DataFrame([{'foo': 'bar'}]);
let ds_foo = df['foo'];
ds_foo.apply(val => val + '2', { inplace: true });
df['foo'] = ds_foo;       // <- this seems to work as data in the foo column appears updated in the browser interactive console
let ds_foo2 = df['foo'];  // <- but column can no longer be retrieved using the DataFrame's get accessor

Note that use of the column() method yields identical behavior.

Expected behavior Return of the Series object containing 'foo' column values when let ds_foo2 = df['foo'] is executed.

Desktop:

  • OS: Fedora 35 Linux
  • Firefox 105.0.1 (64-bit), Chrome 106.0.5249.91 (64-bit), Brave v1.44.105 (64-bit)
  • danfo.js v1.1.1

Additional context Observed behavior was consistent across all tested browsers (Firefox, Chrome, Brave). Inspecting df after df['foo'] = ds_foo reveals that the column values are updated as expected:

t {$dataIncolumnFormat: Array(1), $index: Array(1), $columns: Array(1), $dtypes: Array(1), $isSeries: false, …}
  $columns: ['foo']
  $config: e {tableDisplayConfig: {…}, tableMaxRow: 10, tableMaxColInConsole: 10, dtypeTestLim: 20, lowMemoryMode: false}
  $data: Array(1)
    0: ['bar2']
    length: 1
    [[Prototype]]: Array(0)
  $dataIncolumnFormat: [t]
  $dtypes: ['string']
  $index: [0]
  $isSeries: false

Note: Possible duplicate of issue #499

jm-boley avatar Oct 04 '22 01:10 jm-boley

Please note that as an alternative the addColumn() method does appear to work:

df = df.addColumn('foo', ds_foo);

jm-boley avatar Oct 04 '22 02:10 jm-boley