Skip to content

Commit df89bf9

Browse files
committed
Set header to true as default in readCSV
1 parent 64597e1 commit df89bf9

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ test/fixtures/titanicO*
44
danfojs-node/test/samples/test*
55
danfojs-node/test/samples/titanicO*
66
danfojs-node/test/samples/sampleO*
7+
src/danfojs-node/test/samples/sampleOut.xlsx
8+
src/danfojs-node/test/samples/test.xlsx
9+
src/danfojs-node/test/samples/testSeries.xlsx

src/danfojs-browser/src/io/io.csv.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { CsvInputOptions, CsvOutputOptionsBrowser } from "../types"
4949
const $readCSV = async (file: any, options?: CsvInputOptions): Promise<DataFrame> => {
5050
return new Promise(resolve => {
5151
Papa.parse(file, {
52+
header: true,
5253
...options,
5354
download: true,
5455
complete: results => {
@@ -79,6 +80,7 @@ const $streamCSV = async (file: string, callback: (df: DataFrame) => void, optio
7980
let count = -1
8081
Papa.parse(file, {
8182
...options,
83+
header: true,
8284
download: true,
8385
step: results => {
8486
const df = new DataFrame([results.data], { index: [count++] });

src/danfojs-node/src/io/io.csv.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ import { CsvInputOptions, CsvOutputOptionsNode } from "../types"
5151
const $readCSV = async (filePath: string, options?: CsvInputOptions): Promise<DataFrame> => {
5252
if (filePath.startsWith("http") || filePath.startsWith("https")) {
5353
return new Promise(resolve => {
54+
const optionsWithDefaults = {
55+
header: true,
56+
...options,
57+
}
58+
5459
const dataStream = request.get(filePath);
55-
const parseStream: any = Papa.parse(Papa.NODE_STREAM_INPUT, options);
60+
const parseStream: any = Papa.parse(Papa.NODE_STREAM_INPUT, optionsWithDefaults);
5661
dataStream.pipe(parseStream);
5762

5863
const data: any = [];
@@ -69,6 +74,7 @@ const $readCSV = async (filePath: string, options?: CsvInputOptions): Promise<Da
6974
return new Promise(resolve => {
7075
const fileStream = fs.createReadStream(filePath)
7176
Papa.parse(fileStream, {
77+
header: true,
7278
...options,
7379
complete: results => {
7480
const df = new DataFrame(results.data);
@@ -97,10 +103,14 @@ const $readCSV = async (filePath: string, options?: CsvInputOptions): Promise<Da
97103
const $streamCSV = async (filePath: string, callback: (df: DataFrame) => void, options?: CsvInputOptions): Promise<null> => {
98104

99105
if (filePath.startsWith("http") || filePath.startsWith("https")) {
106+
const optionsWithDefaults = {
107+
header: true,
108+
...options,
109+
}
100110
return new Promise(resolve => {
101111
let count = -1
102112
const dataStream = request.get(filePath);
103-
const parseStream: any = Papa.parse(Papa.NODE_STREAM_INPUT, options);
113+
const parseStream: any = Papa.parse(Papa.NODE_STREAM_INPUT, optionsWithDefaults);
104114
dataStream.pipe(parseStream);
105115

106116
parseStream.on("data", (chunk: any) => {
@@ -119,6 +129,7 @@ const $streamCSV = async (filePath: string, callback: (df: DataFrame) => void, o
119129
return new Promise(resolve => {
120130
let count = -1
121131
Papa.parse(fileStream, {
132+
header: true,
122133
...options,
123134
step: results => {
124135
const df = new DataFrame([results.data], { index: [count++] });

0 commit comments

Comments
 (0)