@@ -2742,68 +2742,6 @@ describe("DataFrame", function () {
27422742 } ) ;
27432743 } ) ;
27442744
2745- // describe("IO outputs", function () {
2746- // it("toExcel works", async function () {
2747- // const data = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
2748- // const df = new dfd.DataFrame(data, { columns: ["a", "b", "c", "d"] });
2749-
2750- // const filePath = path.join(process.cwd(), "test", "samples", "test.xlsx");
2751- // df.toExcel({ filePath })
2752-
2753- // const dfNew = await readExcel(filePath, {});
2754- // assert.equal(fs.existsSync(filePath), true)
2755- // assert.deepEqual(dfNew.columns, [
2756- // 'a',
2757- // 'b',
2758- // 'c',
2759- // 'd',
2760- // ]);
2761- // assert.deepEqual(dfNew.dtypes, [
2762- // 'int32', 'int32',
2763- // 'int32', 'int32',
2764- // ]);
2765- // assert.deepEqual(dfNew.shape, [3, 4])
2766- // });
2767-
2768- // it("toCSV works for specified seperator", async function () {
2769- // const data = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
2770- // let df = new dfd.DataFrame(data, { columns: ["a", "b", "c", "d"] });
2771- // assert.deepEqual(df.toCSV({ sep: "+" }), `a+b+c+d\n1+2+3+4\n5+6+7+8\n9+10+11+12\n`);
2772- // });
2773- // it("toCSV write to local file works", async function () {
2774- // const data = [[1, 2, 3, "4"], [5, 6, 7, "8"], [9, 10, 11, "12"]]
2775- // let df = new dfd.DataFrame(data, { columns: ["a", "b", "c", "d"] });
2776-
2777- // const filePath = path.join(process.cwd(), "test", "samples", "test_write.csv");
2778-
2779- // df.toCSV({ sep: ",", filePath });
2780- // assert.equal(fs.existsSync(filePath), true);
2781- // });
2782- // it("toJSON works for row format", async function () {
2783- // const data = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
2784- // const df = new dfd.DataFrame(data, { columns: ["a", "b", "c", "d"] });
2785- // const expected = {
2786- // "a": [1, 5, 9],
2787- // "b": [2, 6, 10],
2788- // "c": [3, 7, 11],
2789- // "d": [4, 8, 12],
2790- // }
2791- // const json = df.toJSON({ format: "row" })
2792- // assert.deepEqual(json, expected);
2793- // });
2794- // it("toJSON writes file to local path", async function () {
2795- // const data = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
2796- // const df = new dfd.DataFrame(data, { columns: ["a", "b", "c", "d"] });
2797-
2798- // const rowfilePath = path.join(process.cwd(), "test", "samples", "test_row_write.json");
2799- // const colfilePath = path.join(process.cwd(), "test", "samples", "test_col_write.json");
2800-
2801- // df.toJSON({ format: "row", filePath: rowfilePath })
2802- // df.toJSON({ format: "column", filePath: colfilePath })
2803- // assert.equal(fs.existsSync(rowfilePath), true);
2804- // assert.equal(fs.existsSync(colfilePath), true);
2805- // });
2806- // })
28072745
28082746 describe ( "getDummies" , function ( ) {
28092747 it ( "getDummies works on DataFrame" , function ( ) {
@@ -2902,5 +2840,51 @@ describe("DataFrame", function () {
29022840 } ) ;
29032841 } ) ;
29042842
2843+ describe ( "iat" , function ( ) {
2844+ it ( "iat works on DataFrame" , function ( ) {
2845+ const data = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] ] ;
2846+ const columns = [ "a" , "b" , "c" , "d" ] ;
2847+ const df = new dfd . DataFrame ( data , { columns } ) ;
2848+ assert . equal ( df . iat ( 0 , 0 ) , 1 ) ;
2849+ assert . equal ( df . iat ( 1 , 1 ) , 6 ) ;
2850+ assert . equal ( df . iat ( 2 , 3 ) , 12 ) ;
2851+ } ) ;
2852+ it ( "throws error on string indices" , function ( ) {
2853+ const data = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] ] ;
2854+ const columns = [ "a" , "b" , "c" , "d" ] ;
2855+ const index = [ "A" , "B" , "C" ] ;
2856+ const df = new dfd . DataFrame ( data , { columns, index } ) ;
2857+ /* @ts -ignore */
2858+ assert . throws ( function ( ) { df . iat ( "A" , 0 ) ; } , Error , "ParamError: row and column index must be an integer. Use .at to get a row or column by label." ) ;
2859+ /* @ts -ignore */
2860+ assert . throws ( function ( ) { df . iat ( 0 , "A" ) ; } , Error , "ParamError: row and column index must be an integer. Use .at to get a row or column by label." ) ;
2861+ } ) ;
2862+ } ) ;
2863+
2864+ describe ( "at" , function ( ) {
2865+ it ( "at works on DataFrame" , function ( ) {
2866+ const data = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] ] ;
2867+ const columns = [ "a" , "b" , "c" , "d" ] ;
2868+ const index = [ "A" , "B" , "C" ] ;
2869+ const df = new dfd . DataFrame ( data , { columns, index } ) ;
2870+ assert . equal ( df . at ( "A" , "a" ) , 1 ) ;
2871+ assert . equal ( df . at ( "B" , "b" ) , 6 ) ;
2872+ assert . equal ( df . at ( "C" , "c" ) , 11 ) ;
2873+
2874+ } ) ;
2875+ it ( "throws error on numeric column index" , function ( ) {
2876+ const data = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] ] ;
2877+ const columns = [ "a" , "b" , "c" , "d" ] ;
2878+ const index = [ 0 , "B" , "C" ] ;
2879+ const df = new dfd . DataFrame ( data , { columns, index } ) ;
29052880
2881+ assert . equal ( df . at ( 0 , "b" ) , 2 ) ;
2882+ /* @ts -ignore */
2883+ assert . throws ( function ( ) { df . at ( 0 , 1 ) ; } , Error , "ParamError: column index must be a string. Use .iat to get a row or column by index." ) ;
2884+ /* @ts -ignore */
2885+ assert . throws ( function ( ) { df . at ( "B" , 0 ) ; } , Error , "ParamError: column index must be a string. Use .iat to get a row or column by index." ) ;
2886+
2887+ } ) ;
2888+
2889+ } ) ;
29062890} ) ;
0 commit comments