danfojs icon indicating copy to clipboard operation
danfojs copied to clipboard

`sf.apply` not working with dates

Open Decezaris opened this issue 2 years ago • 1 comments

Using danfo-node, with node 16...

timestamp is a column created from new Date() instance

const sfHourly = df.column('timestamp').apply((date) => {
    const dt = new Date(date);
    dt.setMinutes(0);
    
    return dt;
});

This code throws the following message TypeError: arr.slice is not a function

Decezaris avatar May 06 '23 16:05 Decezaris

I can confirm this bug comes from is1DArray utility that it only checks if typeof arr as:

if (
            typeof arr[0] == "number" ||
            typeof arr[0] == "string" ||
            typeof arr[0] == "boolean" ||
            arr[0] === null
        ) {
            return true;
        } else {
            return false;
        }

since datetime is an object, so the implementatio wrongly treats array of datetime as 2d Array.

junduck avatar Nov 12 '25 18:11 junduck