Skip to content

Commit 1eeb6af

Browse files
committed
fix #249
specify columns name for DataFrame array append
1 parent 927af89 commit 1eeb6af

File tree

4 files changed

+159
-157
lines changed

4 files changed

+159
-157
lines changed

danfojs-browser/src/core/frame.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ export class DataFrame extends Ndframe {
21572157
`length Mixmatch: The lenght of provided value (${val.length}) does not match the original DataFrame (${this.shape[1]})`
21582158
);
21592159
}
2160-
df2 = new DataFrame(val);
2160+
df2 = new DataFrame(val, { columns:this.columns });
21612161
}
21622162
} else if (utils.__is_object(val)) {
21632163
df2 = new DataFrame(val);

danfojs-node/dist/core/frame.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,9 @@ class DataFrame extends _generic.default {
18611861
throw Error(`length Mixmatch: The lenght of provided value (${val.length}) does not match the original DataFrame (${this.shape[1]})`);
18621862
}
18631863

1864-
df2 = new DataFrame(val);
1864+
df2 = new DataFrame(val, {
1865+
columns: this.columns
1866+
});
18651867
}
18661868
} else if (utils.__is_object(val)) {
18671869
df2 = new DataFrame(val);

danfojs-node/src/core/frame.js

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -597,32 +597,32 @@ export class DataFrame extends Ndframe {
597597
for (let j = 1; j < value.length; j++) {
598598
let curr_val = value[j];
599599
switch (ops) {
600-
case "max":
601-
if (curr_val > temp_val) {
602-
temp_val = curr_val;
603-
temp_data.push(curr_val);
604-
} else {
605-
temp_data.push(temp_val);
606-
}
607-
break;
608-
case "min":
609-
if (curr_val < temp_val) {
610-
temp_val = curr_val;
611-
temp_data.push(curr_val);
612-
} else {
613-
temp_data.push(temp_val);
614-
}
615-
break;
616-
case "sum":
617-
temp_val = temp_val + curr_val;
600+
case "max":
601+
if (curr_val > temp_val) {
602+
temp_val = curr_val;
603+
temp_data.push(curr_val);
604+
} else {
618605
temp_data.push(temp_val);
619-
620-
break;
621-
case "prod":
622-
temp_val = temp_val * curr_val;
606+
}
607+
break;
608+
case "min":
609+
if (curr_val < temp_val) {
610+
temp_val = curr_val;
611+
temp_data.push(curr_val);
612+
} else {
623613
temp_data.push(temp_val);
614+
}
615+
break;
616+
case "sum":
617+
temp_val = temp_val + curr_val;
618+
temp_data.push(temp_val);
619+
620+
break;
621+
case "prod":
622+
temp_val = temp_val * curr_val;
623+
temp_data.push(temp_val);
624624

625-
break;
625+
break;
626626
}
627627
}
628628
data.push(temp_data);
@@ -1657,24 +1657,24 @@ export class DataFrame extends Ndframe {
16571657
}
16581658

16591659
switch (logical_type) {
1660-
case "lt":
1661-
int_vals = tf.tensor(this.values).less(other).arraySync();
1662-
break;
1663-
case "gt":
1664-
int_vals = tf.tensor(this.values).greater(other).arraySync();
1665-
break;
1666-
case "le":
1667-
int_vals = tf.tensor(this.values).lessEqual(other).arraySync();
1668-
break;
1669-
case "ge":
1670-
int_vals = tf.tensor(this.values).greaterEqual(other).arraySync();
1671-
break;
1672-
case "ne":
1673-
int_vals = tf.tensor(this.values).notEqual(other).arraySync();
1674-
break;
1675-
case "eq":
1676-
int_vals = tf.tensor(this.values).equal(other).arraySync();
1677-
break;
1660+
case "lt":
1661+
int_vals = tf.tensor(this.values).less(other).arraySync();
1662+
break;
1663+
case "gt":
1664+
int_vals = tf.tensor(this.values).greater(other).arraySync();
1665+
break;
1666+
case "le":
1667+
int_vals = tf.tensor(this.values).lessEqual(other).arraySync();
1668+
break;
1669+
case "ge":
1670+
int_vals = tf.tensor(this.values).greaterEqual(other).arraySync();
1671+
break;
1672+
case "ne":
1673+
int_vals = tf.tensor(this.values).notEqual(other).arraySync();
1674+
break;
1675+
case "eq":
1676+
int_vals = tf.tensor(this.values).equal(other).arraySync();
1677+
break;
16781678
}
16791679
let bool_vals = utils.__map_int_to_bool(int_vals, 2);
16801680
let df = new DataFrame(bool_vals, {
@@ -1846,27 +1846,27 @@ export class DataFrame extends Ndframe {
18461846
let temp_col = col_values[col_idx];
18471847

18481848
switch (kwargs["dtype"]) {
1849-
case "float32":
1850-
temp_col.map((val) => {
1851-
new_col_values.push(Number(val));
1852-
});
1853-
col_values[col_idx] = new_col_values;
1854-
break;
1855-
case "int32":
1856-
temp_col.map((val) => {
1857-
new_col_values.push(Number(Number(val).toFixed()));
1858-
});
1859-
col_values[col_idx] = new_col_values;
1849+
case "float32":
1850+
temp_col.map((val) => {
1851+
new_col_values.push(Number(val));
1852+
});
1853+
col_values[col_idx] = new_col_values;
1854+
break;
1855+
case "int32":
1856+
temp_col.map((val) => {
1857+
new_col_values.push(Number(Number(val).toFixed()));
1858+
});
1859+
col_values[col_idx] = new_col_values;
18601860

1861-
break;
1862-
case "string":
1863-
temp_col.map((val) => {
1864-
new_col_values.push(String(val));
1865-
});
1866-
col_values[col_idx] = new_col_values;
1867-
break;
1868-
default:
1869-
break;
1861+
break;
1862+
case "string":
1863+
temp_col.map((val) => {
1864+
new_col_values.push(String(val));
1865+
});
1866+
col_values[col_idx] = new_col_values;
1867+
break;
1868+
default:
1869+
break;
18701870
}
18711871

18721872
let new_col_obj = {};
@@ -2160,7 +2160,7 @@ export class DataFrame extends Ndframe {
21602160
`length Mixmatch: The lenght of provided value (${val.length}) does not match the original DataFrame (${this.shape[1]})`
21612161
);
21622162
}
2163-
df2 = new DataFrame(val);
2163+
df2 = new DataFrame(val, { columns:this.columns });
21642164
}
21652165
} else if (utils.__is_object(val)) {
21662166
df2 = new DataFrame(val);

0 commit comments

Comments
 (0)