Skip to content

Commit 2287a0d

Browse files
committed
fix [#239] Dataframe can't drop and rename
update `Object.defineProperty` in `__set_col_property` to contain `configurable` set to `true`
1 parent 927af89 commit 2287a0d

2 files changed

Lines changed: 63 additions & 61 deletions

File tree

danfojs-browser/src/core/frame.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,7 @@ export class DataFrame extends Ndframe {
20712071
col_vals.forEach((col, i) => {
20722072
// self[col_names[i]] = new Series(col, { columns: col_names[i], index: self.index })
20732073
Object.defineProperty(self, col_names[i], {
2074+
configurable: true,
20742075
get() {
20752076
return new Series(col, { columns: col_names[i], index: self.index });
20762077
},

danfojs-node/src/core/frame.js

Lines changed: 62 additions & 61 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 = {};
@@ -2074,6 +2074,7 @@ export class DataFrame extends Ndframe {
20742074
col_vals.forEach((col, i) => {
20752075
// self[col_names[i]] = new Series(col, { columns: col_names[i], index: self.index })
20762076
Object.defineProperty(self, col_names[i], {
2077+
configurable: true,
20772078
get() {
20782079
return new Series(col, { columns: col_names[i], index: self.index });
20792080
},

0 commit comments

Comments
 (0)