Skip to content

Commit 838c340

Browse files
committed
Update reader params and test in io
1 parent 7c55463 commit 838c340

2 files changed

Lines changed: 23 additions & 42 deletions

File tree

danfojs-browser/src/io/reader.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ export const read_json = async (source) => {
4747
*
4848
* * @param {kwargs} kwargs --> {
4949
* source : string, URL or local file path to retreive Excel file.
50-
* sheet_name : string, (Optional) Name of the sheet which u want to parse. Default will be the first sheet.
50+
* sheet : string, (Optional) Name of the sheet which u want to parse. Default will be the first sheet.
5151
* header_index : int, (Optional) Index of the row which represents the header(columns) of the data. Default will be the first non empty row.
5252
* data_index : int, (Optional)Index of the row from which actual data(content) starts. Default will be the next row of `header_index`
5353
* }
5454
* @returns {Promise} DataFrame structure of parsed Excel data
5555
*/
56-
export const read_excel = async (kwargs) => {
57-
let { source, sheet_name, header_index, data_index } = kwargs;
56+
export const read_excel = async (source, configs = {}) => {
57+
let { sheet, header_index, data_index } = configs;
5858
let workbook;
5959
if (!header_index) {
6060
//default header_index
@@ -72,7 +72,7 @@ export const read_excel = async (kwargs) => {
7272

7373

7474
// Parse worksheet from workbook
75-
const worksheet = workbook.Sheets[sheet_name || workbook.SheetNames[0]];
75+
const worksheet = workbook.Sheets[sheet || workbook.SheetNames[0]];
7676
let range = XLSX.utils.decode_range(worksheet["!ref"]);
7777
let column_names = [],
7878
data = [];

danfojs-browser/tests/io/reader.js

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,25 @@ describe("read_csv", async function () {
1212
});
1313
});
1414

15-
// describe("read_json", async function () {
16-
// this.timeout(10000); // all tests in this suite get 10 seconds before timeout
17-
// it("reads a json file from source over the internet", async function () {
18-
// const jUrl =
19-
// "https://raw.githubusercontent.com/risenW/Tensorflowjs_Projects/master/recommender-sys/Python-Model/web_book_data.json";
20-
21-
// dfd.read_json(jUrl).then((df) => {
22-
// const num_of_columns = df.column_names.length;
23-
// assert.equal(num_of_columns, 4);
24-
// });
25-
// });
26-
27-
// it("reads a json file from source from local disk", async function () {
28-
// const jUrl = "danfojs/tests/samples/book.json";
15+
describe("read_json", async function () {
16+
this.timeout(10000); // all tests in this suite get 10 seconds before timeout
17+
it("reads a json file from source over the internet", async function () {
18+
const jUrl =
19+
"https://raw.githubusercontent.com/risenW/Tensorflowjs_Projects/master/recommender-sys/Python-Model/web_book_data.json";
2920

30-
// dfd.read_json(jUrl).then((df) => {
31-
// const num_of_columns = df.column_names.length;
32-
// assert.equal(num_of_columns, 4);
33-
// });
34-
// });
35-
// });
21+
const df = await dfd.read_json(jUrl);
22+
const num_of_columns = df.column_names.length;
23+
assert.equal(num_of_columns, 4);
3624

37-
// describe("read_excel", async function () {
38-
// this.timeout(10000); // all tests in this suite get 10 seconds before timeout
39-
// it("reads an excel file from source over the internet", async function () {
40-
// const remote_url =
41-
// "https://file-examples-com.github.io/uploads/2017/02/file_example_XLS_100.xls";
42-
// dfd.read_excel({ source: remote_url }).then((df) => {
43-
// assert(df.columns.length, 8);
44-
// });
45-
// });
25+
});
26+
});
4627

47-
// it("reads an excel file from source from local disk", async function () {
48-
// const file_url = "danfojs/tests/samples/SampleData.xlsx";
49-
// dfd.read_excel({ source: file_url, header_index: 7, data_index: 8 }).then(
50-
// (df) => {
51-
// assert(df.columns.length, 4);
52-
// }
53-
// );
54-
// });
55-
// });
28+
describe("read_excel", async function () {
29+
this.timeout(10000); // all tests in this suite get 10 seconds before timeout
30+
it("reads an excel file from source over the internet", async function () {
31+
const remote_url =
32+
"https://file-examples-com.github.io/uploads/2017/02/file_example_XLS_100.xls";
33+
const df = await dfd.read_excel(remote_url);
34+
assert(df.columns.length, 8);
35+
});
36+
});

0 commit comments

Comments
 (0)