danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

Unexplained behavior in single column projection

Open qawnaoya opened this issue 3 years ago • 1 comments

Describe the bug

In choose single column;

This isn't work:

var house_ids = df["house_id"]; var tss = df["tsJST1"];

This is work:

var house_ids = df.loc({columns:["house_id"]})["house_id"]; var tss = df.loc({columns:["tsJST1"]})["tsJST1"];

To Reproduce

var house_ids = df["house_id"]; var tss = df["tsJST1"];

Expected behavior

obtaining Series;

qawnaoya avatar Dec 27 '22 06:12 qawnaoya

Initial Data:

let data = [ 
    [ "Alice", 2, new Date("2029-01-01 01:00:00") ],
    [ "Bob", 5, new Date("2019-01-02") ],
    [ "Charlie", 30, new Date("2020-01-03 01:00:20") ],
    [ "Dennis", 89, new Date("2022-02-04 02:16:00") ] 
];

let columns = ["Name", "Count", "Date"]

With this method of setting the column names, I am able to replicate @qawnaoya issue

let df = new dfd.DataFrame(data);
df.$setColumnNames(columns);

// Column names are modified
console.log(df.columns) // ["Name", "Count", "Date"]

df.loc({columns: ["Name"]})["Name"].print() // Returns series
df["Name"].print() // undefined

On initializing the column names in the constructor, this issue is not present:

let df = new dfd.DataFrame(data, { columns });

console.log(df.columns) // ["Name", "Count", "Date"]

df.loc({columns: ["Name"]})["Name"].print() // Returns series
df["Name"].print() // Returns series

Can someone please explain if this is the expected behavior?

Infinage avatar May 12 '23 12:05 Infinage