Skip to content

Commit d3d3f48

Browse files
committed
fix indexing to upper bound exclusive
1 parent 49b2938 commit d3d3f48

4 files changed

Lines changed: 14 additions & 181 deletions

File tree

danfojs/src/core/frame.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ export class DataFrame extends Ndframe {
10951095
*/
10961096
groupby(col) {
10971097

1098-
let len = this.shape[0] - 1
1098+
let len = this.shape[0]
10991099

11001100
let column_names = this.column_names
11011101
let col_dict = {};

danfojs/src/core/indexing.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ export const indexLoc = (ndframe, kwargs) => {
3232
}
3333

3434
if (isNaN(Number(row_split[1]))) {
35-
end = ndframe.index.lastIndexOf(row_split[1]) || (ndframe.values.length - 1);
35+
end = ndframe.index.lastIndexOf(row_split[1])-1 || (ndframe.values.length - 1);
3636
} else {
37-
end = Number(row_split[1]) || (ndframe.values.length - 1);
37+
end = Number(row_split[1])-1 || (ndframe.values.length - 1);
3838
}
3939
rows = utils.__range(start, end);
4040
} else {
4141
let start = parseInt(row_split[0]) || 0;
42-
let end = parseInt(row_split[1]) || (ndframe.values.length - 1);
42+
let end = parseInt(row_split[1]) - 1 || (ndframe.values.length - 1);
4343

4444
if (typeof start == "number" && typeof end == "number") {
4545
rows = utils.__range(start, end);
@@ -95,11 +95,11 @@ export const indexLoc = (ndframe, kwargs) => {
9595

9696
if (kwargs["type"] == "iloc" || (row_split[0] == "")) {
9797
start = parseInt(row_split[0]) || 0;
98-
end = parseInt(row_split[1]) || (ndframe.values[0].length - 1);
98+
end = parseInt(row_split[1]) -1 || (ndframe.values[0].length - 1);
9999
} else {
100100

101101
start = parseInt(ndframe.columns.indexOf(row_split[0]));
102-
end = parseInt(ndframe.columns.indexOf(row_split[1]));
102+
end = parseInt(ndframe.columns.indexOf(row_split[1]))-1;
103103
}
104104

105105

danfojs/src/plotting/plot.js

Lines changed: 0 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,178 +1,12 @@
1-
<<<<<<< HEAD
2-
// //perform plotting
3-
// import { newPlot } from 'plotly.js/dist/plotly'
4-
// import { Utils } from "../core/utils"
5-
// import { Series } from "../core/series"
6-
=======
71
//perform plotting
82
// import { newPlot } from 'plotly.js' //comment out when building for Node Version
93
import { Utils } from "../core/utils"
104
import { Series } from "../core/series"
11-
>>>>>>> 6a95f1f8bf10e04a4d78b55fa47ba16fefc96159
125

136
// const utils = new Utils()
147

158

169

17-
<<<<<<< HEAD
18-
// /**
19-
// * Plotting methods and Functions performed on Series and DataFrames
20-
// */
21-
// export class Plot {
22-
// constructor() { }
23-
24-
// plot(ndframe, div, config) {
25-
// let params = Object.keys(config)
26-
// let this_config = {}
27-
28-
// params.forEach(param => {
29-
// this_config[param] = config[param]
30-
// })
31-
32-
// if (!utils.__key_in_object(config, "layout")) {
33-
// this_config['layout'] = {}
34-
// }
35-
36-
// if (ndframe instanceof Series) {
37-
// let trace = {}
38-
39-
// if (this_config['type'] == 'histogram') {
40-
// let x = ndframe.values
41-
// trace["x"] = x
42-
// } else {
43-
// let y = ndframe.values
44-
// trace["y"] = y
45-
// }
46-
47-
// params.forEach(param => {
48-
// trace[param] = config[param]
49-
// })
50-
// newPlot(div, [trace], this_config['layout']);
51-
52-
// } else {
53-
54-
// //DataFrame
55-
// if (utils.__key_in_object(this_config, 'x') && utils.__key_in_object(this_config, 'y')) {
56-
// if (!ndframe.column_names.includes(this_config['x'])) {
57-
// throw Error(`Column Error: ${this_config['x']} not found in columns`)
58-
// }
59-
// if (!ndframe.column_names.includes(this_config['y'])) {
60-
// throw Error(`Column Error: ${this_config['y']} not found in columns`)
61-
// }
62-
63-
64-
// let x = ndframe[this_config['x']].values
65-
// let y = ndframe[this_config['y']].values
66-
67-
// let trace = {
68-
// x: x,
69-
// y: y,
70-
// type: config["type"],
71-
// mode: config["mode"],
72-
// }
73-
74-
// let xaxis = {}; let yaxis = {}
75-
// xaxis['title'] = this_config['x']
76-
// yaxis['title'] = this_config['y']
77-
78-
// this_config['layout']['xaxis'] = xaxis
79-
// this_config['layout']['yaxis'] = yaxis
80-
81-
82-
// newPlot(div, [trace], this_config['layout']);
83-
84-
85-
// } else if (this_config['type'] == 'pie') {
86-
// if (!ndframe.column_names.includes(this_config['values'])) {
87-
// throw Error(`Column Error: ${this_config['values']} not found in columns`)
88-
// }
89-
// if (!ndframe.column_names.includes(this_config['labels'])) {
90-
// throw Error(`Column Error: ${this_config['labels']} not found in columns`)
91-
// }
92-
// let data = [{
93-
// values: ndframe[this_config['values']].values,
94-
// labels: ndframe[this_config['labels']].values,
95-
// type: 'pie'
96-
// }];
97-
98-
// newPlot(div, data, this_config['layout'])
99-
100-
// } else if (this_config['type'] == 'table') {
101-
// let header = {}
102-
// let cells = {}
103-
104-
// header['values'] = ndframe.column_names
105-
// cells['values'] = ndframe.col_data
106-
107-
// if (this_config['header_style']) {
108-
// Object.keys(this_config['header_style']).forEach(param => {
109-
// header[param] = this_config['header_style'][param]
110-
// })
111-
// }
112-
113-
// if (this_config['cell_style']) {
114-
// Object.keys(this_config['cell_style']).forEach(param => {
115-
// header[param] = this_config['cell_style'][param]
116-
// })
117-
// }
118-
// var data = [{
119-
// type: 'table',
120-
// header: header,
121-
// cells: cells
122-
// }]
123-
// newPlot(div, data, this_config['layout']);
124-
125-
// } else if (this_config['type'] == 'box') {
126-
// let cols_2_show = []
127-
// let data = []
128-
129-
// if (this_config['columns'] != undefined) {
130-
// cols_2_show = this_config['columns']
131-
// cols_2_show.forEach(col => {
132-
// if (!ndframe.column_names.includes(col)) {
133-
// throw Error(`Column Error: ${this_config['labels']} not found in columns`)
134-
// }
135-
// })
136-
// } else {
137-
// cols_2_show = ndframe.column_names
138-
// }
139-
140-
141-
// cols_2_show.forEach(col => {
142-
// let col_idx = ndframe.column_names.indexOf(col)
143-
// let trace = []
144-
// trace['y'] = ndframe.col_data[col_idx]
145-
// trace["type"] = 'box'
146-
// trace["name"] = col
147-
148-
// data.push(trace)
149-
// })
150-
// newPlot(div, data, this_config['layout']);
151-
152-
// } else {
153-
// //plot all
154-
// let x = ndframe.index
155-
// let data = []
156-
// ndframe.column_names.forEach(c_name => {
157-
// let trace = {}
158-
// trace["x"] = x
159-
// trace["y"] = ndframe[c_name].values
160-
// trace['name'] = c_name
161-
// params.forEach(param => {
162-
// trace[param] = config[param]
163-
// })
164-
// data.push(trace)
165-
166-
// })
167-
// newPlot(div, data, this_config['layout']);
168-
// }
169-
170-
171-
// }
172-
// }
173-
174-
// }
175-
=======
17610
/**
17711
* Plotting methods and Functions performed on Series and DataFrames
17812
*/
@@ -1026,4 +860,3 @@ export class Plot {
1026860

1027861

1028862
}
1029-
>>>>>>> 6a95f1f8bf10e04a4d78b55fa47ba16fefc96159

danfojs/tests/core/frame.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ describe("DataFrame", function () {
191191
let df = new DataFrame(data, { columns: cols })
192192

193193
let col_df = df.loc({ "rows": ["0:2"], "columns": ["B:C"] })
194-
let col_data = [[2, 3], [5, 6], [30, 40]]
194+
let col_data = [[2], [5]]
195195

196196
assert.deepEqual(col_df.values, col_data)
197197

@@ -202,7 +202,7 @@ describe("DataFrame", function () {
202202
let df = new DataFrame(data, { columns: cols })
203203

204204
let col_df = df.loc({ "rows": ["0:2"], "columns": ["B", "C"] })
205-
let col_data = [[2, 3], [5, 6], [30, 40]]
205+
let col_data = [[2, 3], [5, 6]]
206206

207207
assert.deepEqual(col_df.values, col_data)
208208

@@ -213,7 +213,7 @@ describe("DataFrame", function () {
213213
let df = new DataFrame(data, { columns: cols })
214214

215215
let col_df = df.loc({ "rows": [0, 1], "columns": ["A:C"] })
216-
let col_data = [[1, 2, 3], [4, 5, 6]]
216+
let col_data = [[1, 2], [4, 5]]
217217
assert.deepEqual(col_df.values, col_data)
218218

219219
})
@@ -255,7 +255,7 @@ describe("DataFrame", function () {
255255
let df = new DataFrame(data)
256256
df.set_index({ key: ["a", "b", "c", "d"], inplace: true })
257257
let sub_df = df.loc({ rows: ["a:c"], columns: ["Name", "Count"] })
258-
let expected = [["Apples", 21], ["Mango", 5], ["Banana", 30]]
258+
let expected = [["Apples", 21], ["Mango", 5]]
259259
assert.deepEqual(sub_df.values, expected)
260260

261261
})
@@ -321,7 +321,7 @@ describe("DataFrame", function () {
321321
let df = new DataFrame(data, { columns: cols })
322322

323323
let col_df = df.iloc({ "rows": ["0:2"], "columns": ["1:2"] })
324-
let col_data = [[2, 3], [5, 6], [30, 40]]
324+
let col_data = [[2], [5]]
325325

326326
assert.deepEqual(col_df.values, col_data)
327327

@@ -332,7 +332,7 @@ describe("DataFrame", function () {
332332
let df = new DataFrame(data, { columns: cols })
333333

334334
let col_df = df.iloc({ "rows": ["0:2"], "columns": [1, 2] })
335-
let col_data = [[2, 3], [5, 6], [30, 40]]
335+
let col_data = [[2, 3], [5, 6]]
336336

337337
assert.deepEqual(col_df.values, col_data)
338338

@@ -343,7 +343,7 @@ describe("DataFrame", function () {
343343
let df = new DataFrame(data, { columns: cols })
344344

345345
let col_df = df.iloc({ "rows": [0, 1, 2], "columns": ["1:2"] })
346-
let col_data = [[2, 3], [5, 6], [30, 40]]
346+
let col_data = [[2], [5], [30]]
347347
assert.deepEqual(col_df.values, col_data)
348348

349349
})
@@ -363,7 +363,7 @@ describe("DataFrame", function () {
363363
let df = new DataFrame(data, { columns: cols })
364364

365365
let col_df = df.iloc({ "columns": ["1:2"] })
366-
let col_data = [[2, 3], [5, 6], [30, 40], [89, 78]]
366+
let col_data = [[2], [5], [30], [89]]
367367
assert.deepEqual(col_df.values, col_data)
368368

369369
})

0 commit comments

Comments
 (0)