pola-rs / nodejs-polars

nodejs front-end of polars
https://pola-rs.github.io/nodejs-polars/
MIT License
440 stars 45 forks source link

Support nested object columns #298

Open buzzware opened 23 hours ago

buzzware commented 23 hours ago

Have you tried latest version of polars?

yes

What version of polars are you using?

0.16.0

What operating system are you using polars on?

MacOS 14.7.1

What node version are you using

18.19.1

Describe your bug.

Fails to read javascript object columns

What are the steps to reproduce the behavior?

using jest

import pl from 'nodejs-polars';

const eventData = [
    {id: 1, name: 'one', attributes: {x: 700, colour: 'black'}},
    {id: 2, name: 'two', attributes: {x: 800, colour: 'blue'}},
    {id: 3, name: 'three', attributes: {x: 100, colour: 'red'}}
]
const eventDf = pl.DataFrame(eventData);

test('get nested object column', async () => {
  expect(eventDf.getColumn('name').toArray()).toEqual(eventData.map(e=>e['name']));
  expect(eventDf.getColumn('attributes').toArray()).toMatchObject(eventData.map(e=>e['attributes']));
});

What is the actual behavior?

Error: expect(received).toMatchObject(expected)

- Expected  - 6
+ Received  + 3

  Array [
    Object {
-     "colour": "black",
-     "x": 700,
+     "": null,
    },
    Object {
-     "colour": "blue",
-     "x": 800,
+     "": null,
    },
    Object {
-     "colour": "red",
-     "x": 100,
+     "": null,
    },
  ]

What is the expected behavior?

polars has no trouble extracting the name column as an array, but fails on the attributes column, returning a strange array like [{"": null},{"": null},{"": null}]

Bidek56 commented 5 hours ago

This line is the issue, but not sure how to fix it ATM. Sorry.