javascriptdata / danfojs

Danfo.js is an open source, JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.
https://danfo.jsdata.org/
MIT License
4.81k stars 209 forks source link

Leading Zeros Are Removed After dtypes Set to "string" #642

Open chunkangwong opened 5 months ago

chunkangwong commented 5 months ago

Describe the bug When using readCSV and readExcel, with a CSV file that contains zero-leading numbers, the leading zeros are not preserved even after setting dtypes to string

To Reproduce Steps to reproduce the behavior:

  1. Prepare the following .csv file:

./sample.csv

codes
012345
067890
import { readCSV, toJSON } from "danfojs";

const df = await readCSV("./sample.csv", { 
    frameConfig: {
        dtypes: ["string"],
    },
});
const data = toJSON(df);
console.log(data) // [{ codes: 12345 }, { codes: 67890 }]

Expected behavior Leading-zeros should be retained if dtypes is string

Desktop (please complete the following information):