danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

error: File format not supported! while trying to reassign a column.

Open SalamanderXing opened this issue 2 years ago • 2 comments

Describe the bug I'm trying to transform a column of a DataFrame:

import dfd from "danfojs-node";

const df = new dfd.DataFrame({
  a: [1, 2, 3],
  b: ["a", "b", "c"],
});

// ** METHOD 1 **
df["b"] = df["b"].map((value) => value.toUpperCase());

console.log(df["b"].values());
// error: File format not supported!

// ** METHOD 2 ** 
const transformed = df["b"].map((value) => value.toUpperCase());
df.addColumn(
  "b",
  transformed,
  { inplace: true },
);

console.log(df["b"].values());
// error: File format not supported!

Full error stack trace:

                throw new Error("File format not supported!");
                      ^

Error: File format not supported!
    at Series.NDframe (/home/bluesk/Documents/news_aggregator/news_
anfojs-base/core/generic.js:100:23)
    at new Series (/home/bluesk/Documents/news_aggregator/news_aggr
js-base/core/series.js:134:28)
    at DataFrame.$getColumnData (/home/bluesk/Documents/news_aggreg
ode/dist/danfojs-base/core/frame.js:196:24)
    at DataFrame.get (/home/bluesk/Documents/news_aggregator/news_a
nfojs-base/core/frame.js:147:37)
    at file:///home/bluesk/Documents/news_aggregator/news_aggregato
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:
    at async loadESM (node:internal/process/esm_loader:34:7)
    

To Reproduce Run the above code.

Expected behavior No error should be raised, I should be able to access the 'b' column and its values.

Desktop (please complete the following information):

  • OS: Linux
  • Nodejs Node.js v20.9.0

SalamanderXing avatar Nov 06 '23 16:11 SalamanderXing

Up, facing the same issue

vivere-dally avatar Aug 27 '24 18:08 vivere-dally

I can confirm this is a bug. However, your code is wrong, you should use df["b"].values instead of df["b"].values() this is the full reproducible code:

import dfd from "danfojs-node";

const df = new dfd.DataFrame({
  a: [1, 2, 3],
  b: ["a", "b", "c"],
});

// ** METHOD 1 **
df["b"] = df["b"].map((value) => value.toUpperCase());

console.log(df["b"].values);
// error: File format not supported!

// ** METHOD 2 ** 
const transformed = df["b"].map((value) => value.toUpperCase());
df.addColumn(
  "b",
  transformed,
  { inplace: true },
);

console.log(df["b"].values);

This bug comes from the proxy column setter $setColumnData, it wrongly assigns arr to the column instead of extracted values of arr.

You can simply trigger this by any column assignment:

df["b"] = df["b"]; // now df["b"] is broken
console.log(df["a"]); // column a still fine but object invariance of df is broken

I'll create a fix for this in a minute.

junduck avatar Nov 12 '25 16:11 junduck