Skip to content

Commit 68825f4

Browse files
author
minjk-bl
committed
Add drop=True option for reset_index on Bind, Reshape app
1 parent 39d01d7 commit 68825f4

4 files changed

Lines changed: 43 additions & 20 deletions

File tree

html/m_apps/bind.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
<label for="vp_bdAllocateTo" class="w100">Allocate to</label>
8989
<input type="text" id="vp_bdAllocateTo" placeholder="New variable name">
9090
<label><input type="checkbox" id="vp_bdResetIndex"><span>Reset Index</span></label>
91+
<select id="vp_bdWithoutColumn" class="vp-select" style="width: 130px;">
92+
<option value="True" selected>Without column</option>
93+
<option value="">With column</option>
94+
</select>
9195
</div>
9296
</div>
9397
</body>

html/m_apps/reshape.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
<label for="vp_rsAllocateTo" class="w100">Allocate to</label>
7777
<input type="text" id="vp_rsAllocateTo" placeholder="New variable name">
7878
<label><input type="checkbox" id="vp_rsResetIndex"><span>Reset Index</span></label>
79+
<select id="vp_rsWithoutColumn" class="vp-select" style="width: 130px;">
80+
<option value="True" selected>Without column</option>
81+
<option value="">With column</option>
82+
</select>
7983
</div>
8084
</div>
8185
</body>

js/m_apps/Bind.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define([
2929
_init() {
3030
super._init();
3131
/** Write codes executed before rendering */
32-
this.config.sizeLevel = 1;
32+
this.config.sizeLevel = 2;
3333

3434
this.howList = [
3535
{ label: 'Inner', value: 'inner', desc: 'Inner join' },
@@ -66,6 +66,7 @@ define([
6666
userOption: '',
6767
allocateTo: '',
6868
resetIndex: false,
69+
withoutColumn: 'True',
6970
...this.state
7071
}
7172
this.popup = {
@@ -306,6 +307,11 @@ define([
306307
$(document).on('change', this.wrapSelector('#vp_bdResetIndex'), function() {
307308
that.state.resetIndex = $(this).prop('checked');
308309
});
310+
311+
// with/without column select event
312+
$(this.wrapSelector('#vp_bdWithoutColumn')).on('change', function() {
313+
that.state.withoutColumn = $(this).val();
314+
});
309315
}
310316

311317
templateForBody() {
@@ -441,7 +447,7 @@ define([
441447
generateCode() {
442448
var code = new com_String();
443449
var {
444-
type, concat, merge, allocateTo, resetIndex, userOption
450+
type, concat, merge, allocateTo, resetIndex, withoutColumn, userOption
445451
} = this.state;
446452

447453
//====================================================================
@@ -470,13 +476,6 @@ define([
470476
code.append(', sort=True');
471477
}
472478

473-
//====================================================================
474-
// Reset index
475-
//====================================================================
476-
if (resetIndex) {
477-
code.append(', ignore_index=True');
478-
}
479-
480479
//====================================================================
481480
// User option
482481
//====================================================================
@@ -485,6 +484,7 @@ define([
485484
}
486485

487486
code.append(')');
487+
488488
} else {
489489
//====================================================================
490490
// Merge
@@ -538,11 +538,15 @@ define([
538538
}
539539

540540
code.append(')');
541-
542-
//====================================================================
543-
// Reset index
544-
//====================================================================
545-
if (resetIndex) {
541+
}
542+
543+
//====================================================================
544+
// Reset index
545+
//====================================================================
546+
if (resetIndex) {
547+
if (withoutColumn === 'True') {
548+
code.append('.reset_index(drop=True)');
549+
} else {
546550
code.append('.reset_index()');
547551
}
548552
}
@@ -557,7 +561,7 @@ define([
557561

558562
loadState() {
559563
var {
560-
type, concat, merge, userOption, allocateTo, resetIndex
564+
type, concat, merge, userOption, allocateTo, resetIndex, withoutColumn
561565
} = this.state;
562566

563567
// type
@@ -599,6 +603,7 @@ define([
599603
$(this.wrapSelector('#vp_bdUserOption')).val(userOption);
600604
$(this.wrapSelector('#vp_bdAllocateTo')).val(allocateTo);
601605
$(this.wrapSelector('#vp_bdResetIndex')).prop('checked', resetIndex);
606+
$(this.wrapSelector('#vp_bdWithoutColumn')).val(withoutColumn);
602607

603608
$(this.wrapSelector('.vp-bd-type-box')).hide();
604609
$(this.wrapSelector('.vp-bd-type-box.' + type)).show();

js/m_apps/Reshape.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ define([
2929
_init() {
3030
super._init();
3131
/** Write codes executed before rendering */
32-
this.config.sizeLevel = 1;
32+
this.config.sizeLevel = 2;
3333

3434
this.state = {
3535
variable: '',
3636
type: 'pivot',
3737
resetIndex: false,
38+
withoutColumn: 'True',
3839
pivot: {
3940
index: [],
4041
columns: [],
@@ -219,7 +220,11 @@ define([
219220
$(document).on('change', this.wrapSelector('#vp_rsResetIndex'), function() {
220221
that.state.resetIndex = $(this).prop('checked');
221222
});
222-
223+
224+
// with/without column select event
225+
$(this.wrapSelector('#vp_rsWithoutColumn')).on('change', function() {
226+
that.state.withoutColumn = $(this).val();
227+
});
223228

224229
}
225230

@@ -290,7 +295,7 @@ define([
290295
this.loadVariableList();
291296

292297
var {
293-
variable, type, pivot, melt, userOption, allocateTo, resetIndex
298+
variable, type, pivot, melt, userOption, allocateTo, resetIndex, withoutColumn
294299
} = this.state;
295300

296301
$(this.wrapSelector('#vp_rsDataframe')).val(variable);
@@ -316,6 +321,7 @@ define([
316321
// allocateTo
317322
$(this.wrapSelector('#vp_rsAllocateTo')).val(allocateTo);
318323
$(this.wrapSelector('#vp_rsResetIndex')).prop('checked', resetIndex);
324+
$(this.wrapSelector('#vp_rsWithoutColumn')).val(withoutColumn);
319325
}
320326

321327
/**
@@ -415,7 +421,7 @@ define([
415421

416422
generateCode() {
417423
var code = new com_String();
418-
var { variable, type, userOption, allocateTo, resetIndex, pivot, melt } = this.state;
424+
var { variable, type, userOption, allocateTo, resetIndex, withoutColumn, pivot, melt } = this.state;
419425

420426
//====================================================================
421427
// Allocation
@@ -544,7 +550,11 @@ define([
544550
// Reset index
545551
//====================================================================
546552
if (resetIndex) {
547-
code.append('.reset_index()');
553+
if (withoutColumn === 'True') {
554+
code.append('.reset_index(drop=True)');
555+
} else {
556+
code.append('.reset_index()');
557+
}
548558
}
549559

550560
if (allocateTo && allocateTo != '') {

0 commit comments

Comments
 (0)