Skip to content

Commit 7c503fd

Browse files
author
minjk-bl
committed
Fix astype and dropna on Frame app
1 parent e449bb9 commit 7c503fd

File tree

1 file changed

+58
-33
lines changed

1 file changed

+58
-33
lines changed

visualpython/js/m_apps/Frame.js

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,15 @@ define([
862862
let tag = $(this).closest('.vp-inner-popup-sortby-item');
863863
tag.insertAfter(tag.next());
864864
});
865+
} else if (menuType === FRAME_EDIT_TYPE.DROP_NA) {
866+
$(this.wrapSelector('.vp-inner-popup-how')).on('change', function() {
867+
let val = $(this).val();
868+
if (val === '') {
869+
$(that.wrapSelector('.vp-inner-popup-thresh')).prop('disabled', false);
870+
} else {
871+
$(that.wrapSelector('.vp-inner-popup-thresh')).prop('disabled', true);
872+
}
873+
});
865874
}
866875

867876
}
@@ -1585,7 +1594,12 @@ define([
15851594
content.appendFormatLine('<thead style="height: 30px"><th>{0}</th><th>{1}</th><th class="{2}">{3}</th></thead>'
15861595
, 'Column', 'Data type', 'vp-orange-text', 'New data type');
15871596
content.appendLine('<tbody>');
1588-
this.state.selected.forEach((col, idx) => {
1597+
let selectedList = this.state.selected;
1598+
if (selectedList.length === 0) {
1599+
// select all
1600+
selectedList = this.state.columnList;
1601+
}
1602+
selectedList.forEach((col, idx) => {
15891603
content.appendLine('<tr>');
15901604
content.appendFormatLine('<td title="{0}">{1}</td>', col.label, col.label);
15911605
content.appendFormatLine('<td><input type="text" value="{0}" readonly/></td>', col.type);
@@ -1859,25 +1873,25 @@ define([
18591873
pandasObject: this.state.tempObj,
18601874
selectedColumns: [ com_util.convertToStr(contentState.name, contentState.nameastext) ],
18611875
config: { name: 'Subset' } },
1862-
{
1863-
useInputVariable: true,
1864-
useInputColumns: true,
1865-
targetSelector: this.wrapSelector('.vp-inner-popup-subset'),
1866-
pageThis: this,
1867-
allowSubsetTypes: ['iloc', 'loc'],
1868-
beforeOpen: function(subsetThis) {
1869-
let contentState = that.getPopupContent(type);
1870-
let name = com_util.convertToStr(contentState.name, contentState.nameastext);
1871-
subsetThis.state.selectedColumns = [ name ];
1872-
},
1873-
finish: function(code) {
1874-
that.subsetCm.setValue(code);
1875-
that.subsetCm.save();
1876-
setTimeout(function () {
1877-
that.subsetCm.refresh();
1878-
}, 1);
1879-
}
1880-
});
1876+
{
1877+
useInputVariable: true,
1878+
useInputColumns: true,
1879+
targetSelector: this.wrapSelector('.vp-inner-popup-subset'),
1880+
pageThis: this,
1881+
allowSubsetTypes: ['iloc', 'loc'],
1882+
beforeOpen: function(subsetThis) {
1883+
let contentState = that.getPopupContent(type);
1884+
let name = com_util.convertToStr(contentState.name, contentState.nameastext);
1885+
subsetThis.state.selectedColumns = [ name ];
1886+
},
1887+
finish: function(code) {
1888+
that.subsetCm.setValue(code);
1889+
that.subsetCm.save();
1890+
setTimeout(function () {
1891+
that.subsetCm.refresh();
1892+
}, 1);
1893+
}
1894+
});
18811895
// initial code
18821896
var code = this.subsetEditor.generateCode();
18831897
this.subsetCm.setValue(code);
@@ -2086,12 +2100,19 @@ define([
20862100
content['ascending'] = $(this.wrapSelector('.vp-inner-popup-isascending')).val();
20872101
break;
20882102
case FRAME_EDIT_TYPE.AS_TYPE:
2089-
this.state.selected.forEach((col, idx) => {
2103+
let selectedList = this.state.selected;
2104+
if (selectedList.length === 0) {
2105+
// select all
2106+
selectedList = this.state.columnList;
2107+
}
2108+
selectedList.forEach((col, idx) => {
20902109
var value = $(this.wrapSelector('.vp-inner-popup-astype'+idx)).val();
2091-
content[idx] = {
2092-
label: col.code,
2093-
value: value
2094-
};
2110+
if (value !== undefined && value !== '') {
2111+
content[idx] = {
2112+
label: col.code,
2113+
value: value
2114+
};
2115+
}
20952116
});
20962117
break;
20972118
case FRAME_EDIT_TYPE.DISCRETIZE:
@@ -2294,22 +2315,26 @@ define([
22942315
}
22952316
break;
22962317
case FRAME_EDIT_TYPE.DROP_NA:
2297-
var locObj = '';
2318+
var dropNAOptions = [];
22982319
if (axis == FRAME_AXIS.ROW) {
2299-
code.appendFormat("{0}.loc[[{1}],:].dropna(axis=0", tempObj, selectedName);
2320+
dropNAOptions.push("axis=1");
23002321
} else {
2301-
code.appendFormat("{0}.loc[:,[{1}]].dropna(axis=1", tempObj, selectedName);
2322+
dropNAOptions.push("axis=0");
2323+
}
2324+
if (selectedName && selectedName !== '') {
2325+
dropNAOptions.push(com_util.formatString("subset=[{0}]", selectedName));
23022326
}
23032327
if (content.how && content.how !== '') {
2304-
code.appendFormat(", how='{0}'", content.how);
2328+
dropNAOptions.push(com_util.formatString("how='{0}'", content.how));
23052329
}
23062330
if (content.thresh && content.thresh !== '') {
2307-
code.appendFormat(", thresh={0}", content.thresh);
2331+
dropNAOptions.push(com_util.formatString("thresh={0}", content.thresh));
23082332
}
23092333
if (content.ignore_index && content.ignore_index !== '') {
2310-
code.appendFormat(", ignore_index={0}", content.ignore_index);
2334+
dropNAOptions.push(com_util.formatString("ignore_index={0}", content.ignore_index));
23112335
}
2312-
code.append(", inplace=True)");
2336+
dropNAOptions.push("inplace=True");
2337+
code.appendFormat("{0}.dropna({1})", tempObj, dropNAOptions.join(', '));
23132338
break;
23142339
case FRAME_EDIT_TYPE.DROP_DUP:
23152340
let dropDupOptions = [];
@@ -2322,7 +2347,7 @@ define([
23222347
if (content.ignore_index && content.ignore_index !== '') {
23232348
dropDupOptions.push(com_util.formatString("ignore_index={0}", content.ignore_index));
23242349
}
2325-
dropDupOptions.push(com_util.formatString("inplace=True"));
2350+
dropDupOptions.push("inplace=True");
23262351
code.appendFormat("{0}.drop_duplicates({1})", tempObj, dropDupOptions.join(', '));
23272352
break;
23282353
case FRAME_EDIT_TYPE.DROP_OUT:

0 commit comments

Comments
 (0)