Skip to content

Commit

Permalink
Merge pull request #209 from opensource9ja/fix/col-slicing
Browse files Browse the repository at this point in the history
Fixes #203 bug in column slicing index generation
  • Loading branch information
risenW authored May 30, 2021
2 parents 5285e4f + aaeadd2 commit ee78805
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 147 deletions.
30 changes: 15 additions & 15 deletions danfojs-browser/src/core/indexing.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ export const indexLoc = (ndframe, kwargs) => {
//console.log("here", kwargs["rows"].length)
if (kwargs["rows"][0].includes(":")) {

let row_split = kwargs["rows"][0].split(":");
let column_split = kwargs["rows"][0].split(":");

if (kwargs['type'] == 'loc') {
//get index of first and last occurence of label
let start, end;
if (isNaN(Number(row_split[0]))) {
start = ndframe.index.indexOf(row_split[0]);
if (isNaN(Number(column_split[0]))) {
start = ndframe.index.indexOf(column_split[0]);
} else {
start = Number(row_split[0]);
start = Number(column_split[0]);
}

if (isNaN(Number(row_split[1]))) {
end = ndframe.index.lastIndexOf(row_split[1]) - 1 || (ndframe.values.length - 1);
if (isNaN(Number(column_split[1]))) {
end = ndframe.index.lastIndexOf(column_split[1]) - 1 || (ndframe.values.length - 1);
} else {
end = Number(row_split[1]) - 1 || (ndframe.values.length - 1);
end = Number(column_split[1]) - 1 || (ndframe.values.length - 1);
}
rows = utils.__range(start, end);
} else {
let start = parseInt(row_split[0]) || 0;
let end = parseInt(row_split[1]) - 1 || (ndframe.values.length - 1);
let start = parseInt(column_split[0]) || 0;
let end = parseInt(column_split[1]) - 1 || (ndframe.values.length - 1);

if (typeof start == "number" && typeof end == "number") {
rows = utils.__range(start, end);
Expand Down Expand Up @@ -90,16 +90,16 @@ export const indexLoc = (ndframe, kwargs) => {
if (Array.isArray(kwargs["columns"])) {
if (kwargs["columns"].length == 1 && kwargs["columns"][0].includes(":")) {

let row_split = kwargs["columns"][0].split(":");
let column_split = kwargs["columns"][0].split(":");
let start, end;

if (kwargs["type"] == "iloc" || (row_split[0] == "")) {
start = parseInt(row_split[0]) || 0;
end = parseInt(row_split[1]) - 1 || (ndframe.values[0].length - 1);
if (kwargs["type"] == "iloc" || (column_split[0] == "")) {
start = parseInt(column_split[0]) || 0;
end = parseInt(column_split[1]) - 1 === 0 ? 0 : parseInt(column_split[1]) - 1;
} else {

start = parseInt(ndframe.columns.indexOf(row_split[0]));
end = parseInt(ndframe.columns.indexOf(row_split[1])) - 1;
start = parseInt(ndframe.columns.indexOf(column_split[0]));
end = parseInt(ndframe.columns.indexOf(column_split[1])) - 1;
}


Expand Down
31 changes: 16 additions & 15 deletions danfojs-node/dist/core/indexing.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ const indexLoc = (ndframe, kwargs) => {
if (Array.isArray(kwargs["rows"])) {
if (kwargs["rows"].length == 1 && typeof kwargs["rows"][0] == "string") {
if (kwargs["rows"][0].includes(":")) {
let row_split = kwargs["rows"][0].split(":");
let column_split = kwargs["rows"][0].split(":");

if (kwargs['type'] == 'loc') {
let start, end;

if (isNaN(Number(row_split[0]))) {
start = ndframe.index.indexOf(row_split[0]);
if (isNaN(Number(column_split[0]))) {
start = ndframe.index.indexOf(column_split[0]);
} else {
start = Number(row_split[0]);
start = Number(column_split[0]);
}

if (isNaN(Number(row_split[1]))) {
end = ndframe.index.lastIndexOf(row_split[1]) - 1 || ndframe.values.length - 1;
if (isNaN(Number(column_split[1]))) {
end = ndframe.index.lastIndexOf(column_split[1]) - 1 || ndframe.values.length - 1;
} else {
end = Number(row_split[1]) - 1 || ndframe.values.length - 1;
end = Number(column_split[1]) - 1 || ndframe.values.length - 1;
}

rows = utils.__range(start, end);
} else {
let start = parseInt(row_split[0]) || 0;
let end = parseInt(row_split[1]) - 1 || ndframe.values.length - 1;
let start = parseInt(column_split[0]) || 0;
let end = parseInt(column_split[1]) - 1 || ndframe.values.length - 1;

if (typeof start == "number" && typeof end == "number") {
rows = utils.__range(start, end);
Expand Down Expand Up @@ -84,15 +84,16 @@ const indexLoc = (ndframe, kwargs) => {
if (Object.prototype.hasOwnProperty.call(kwargs, "columns")) {
if (Array.isArray(kwargs["columns"])) {
if (kwargs["columns"].length == 1 && kwargs["columns"][0].includes(":")) {
let row_split = kwargs["columns"][0].split(":");
let column_split = kwargs["columns"][0].split(":");
let start, end;

if (kwargs["type"] == "iloc" || row_split[0] == "") {
start = parseInt(row_split[0]) || 0;
end = parseInt(row_split[1]) - 1 || ndframe.values[0].length - 1;
if (kwargs["type"] == "iloc" || column_split[0] == "") {
start = parseInt(column_split[0]) || 0;
end = parseInt(column_split[1]) - 1 === 0 ? 0 : parseInt(column_split[1]) - 1;
console.log(start, end);
} else {
start = parseInt(ndframe.columns.indexOf(row_split[0]));
end = parseInt(ndframe.columns.indexOf(row_split[1])) - 1;
start = parseInt(ndframe.columns.indexOf(column_split[0]));
end = parseInt(ndframe.columns.indexOf(column_split[1])) - 1;
}

if (typeof start == "number" && typeof end == "number") {
Expand Down
31 changes: 16 additions & 15 deletions danfojs-node/src/core/indexing.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ export const indexLoc = (ndframe, kwargs) => {
//console.log("here", kwargs["rows"].length)
if (kwargs["rows"][0].includes(":")) {

let row_split = kwargs["rows"][0].split(":");
let column_split = kwargs["rows"][0].split(":");

if (kwargs['type'] == 'loc') {
//get index of first and last occurence of label
let start, end;
if (isNaN(Number(row_split[0]))) {
start = ndframe.index.indexOf(row_split[0]);
if (isNaN(Number(column_split[0]))) {
start = ndframe.index.indexOf(column_split[0]);
} else {
start = Number(row_split[0]);
start = Number(column_split[0]);
}

if (isNaN(Number(row_split[1]))) {
end = ndframe.index.lastIndexOf(row_split[1]) - 1 || (ndframe.values.length - 1);
if (isNaN(Number(column_split[1]))) {
end = ndframe.index.lastIndexOf(column_split[1]) - 1 || (ndframe.values.length - 1);
} else {
end = Number(row_split[1]) - 1 || (ndframe.values.length - 1);
end = Number(column_split[1]) - 1 || (ndframe.values.length - 1);
}
rows = utils.__range(start, end);
} else {
let start = parseInt(row_split[0]) || 0;
let end = parseInt(row_split[1]) - 1 || (ndframe.values.length - 1);
let start = parseInt(column_split[0]) || 0;
let end = parseInt(column_split[1]) - 1 || (ndframe.values.length - 1);

if (typeof start == "number" && typeof end == "number") {
rows = utils.__range(start, end);
Expand Down Expand Up @@ -90,16 +90,17 @@ export const indexLoc = (ndframe, kwargs) => {
if (Array.isArray(kwargs["columns"])) {
if (kwargs["columns"].length == 1 && kwargs["columns"][0].includes(":")) {

let row_split = kwargs["columns"][0].split(":");
let column_split = kwargs["columns"][0].split(":");
let start, end;

if (kwargs["type"] == "iloc" || (row_split[0] == "")) {
start = parseInt(row_split[0]) || 0;
end = parseInt(row_split[1]) - 1 || (ndframe.values[0].length - 1);
if (kwargs["type"] == "iloc" || (column_split[0] == "")) {
start = parseInt(column_split[0]) || 0;
end = parseInt(column_split[1]) - 1 === 0 ? 0 : parseInt(column_split[1]) - 1;
console.log(start, end);
} else {

start = parseInt(ndframe.columns.indexOf(row_split[0]));
end = parseInt(ndframe.columns.indexOf(row_split[1])) - 1;
start = parseInt(ndframe.columns.indexOf(column_split[0]));
end = parseInt(ndframe.columns.indexOf(column_split[1])) - 1;
}


Expand Down
Loading

0 comments on commit ee78805

Please sign in to comment.