@@ -158,7 +158,9 @@ define([
158
158
if ( subsetType == 'loc' || subsetType == 'iloc' || this . state . dataType == 'Series' ) {
159
159
tag . appendFormatLine ( '<option value="{0}">{1}</option>' , 'indexing' , 'Indexing' ) ;
160
160
}
161
- tag . appendFormatLine ( '<option value="{0}">{1}</option>' , 'slicing' , 'Slicing' ) ;
161
+ if ( subsetType == 'subset' || subsetType == 'loc' || subsetType == 'iloc' ) {
162
+ tag . appendFormatLine ( '<option value="{0}">{1}</option>' , 'slicing' , 'Slicing' ) ;
163
+ }
162
164
if ( subsetType == 'subset' || subsetType == 'loc' || subsetType == 'query' ) {
163
165
tag . appendFormatLine ( '<option value="{0}">{1}</option>' , 'condition' , 'Condition' ) ;
164
166
}
@@ -447,7 +449,7 @@ define([
447
449
tag . appendLine ( '<div class="vp-td-line">' ) ;
448
450
tag . appendLine ( this . templateForConditionColumnInput ( colList ) ) ;
449
451
tag . appendFormatLine ( '<select class="{0} {1}">' , 'vp-select s' , 'vp-oper-list' ) ;
450
- var operList = [ '' , '==' , '!=' , 'in ' , 'not in ' , '<' , '<=' , '>' , '>=' ] ;
452
+ var operList = [ '' , '==' , '!=' , 'contains ' , 'not contains ' , '<' , '<=' , '>' , '>=' , 'starts with' , 'ends with '] ;
451
453
operList . forEach ( oper => {
452
454
tag . appendFormatLine ( '<option value="{0}">{1}</option>' , oper , oper ) ;
453
455
} ) ;
@@ -483,25 +485,26 @@ define([
483
485
// .index
484
486
tag . appendFormatLine ( '<option data-code="{0}" value="{1}">{2}</option>' , '.index' , '.index' , 'index' ) ;
485
487
colList . forEach ( col => {
486
- tag . appendFormatLine ( '<option data-code="{0}" value ="{1}">{2 }</option>' ,
487
- col . code , col . value , col . label ) ;
488
+ tag . appendFormatLine ( '<option data-code="{0}" data-dtype ="{1}" value="{2}">{3 }</option>' ,
489
+ col . code , col . dtype , col . value , col . label ) ;
488
490
} ) ;
489
491
tag . appendLine ( '</select>' ) ;
490
492
return tag . toString ( ) ;
491
493
}
492
- templateForConditionCondInput ( category ) {
494
+ templateForConditionCondInput ( category , dtype = 'object' ) {
493
495
var vpCondSuggest = new SuggestInput ( ) ;
494
496
vpCondSuggest . addClass ( 'vp-input m vp-condition' ) ;
495
497
496
498
if ( category && category . length > 0 ) {
497
- vpCondSuggest . setPlaceholder ( " Categorical Dtype ") ;
499
+ vpCondSuggest . setPlaceholder ( ( dtype == 'object' ? ' Categorical' : dtype ) + " dtype ") ;
498
500
vpCondSuggest . setSuggestList ( function ( ) { return category ; } ) ;
499
501
vpCondSuggest . setSelectEvent ( function ( value ) {
500
502
$ ( this . wrapSelector ( ) ) . val ( value ) ;
501
503
$ ( this . wrapSelector ( ) ) . trigger ( 'change' ) ;
502
504
} ) ;
503
505
vpCondSuggest . setNormalFilter ( false ) ;
504
506
} else {
507
+ vpCondSuggest . setPlaceholder ( dtype == '' ?'Value' :( dtype + " dtype" ) ) ;
505
508
}
506
509
return vpCondSuggest . toTagString ( ) ;
507
510
}
@@ -689,6 +692,7 @@ define([
689
692
label : x . location + '' ,
690
693
value : x . location + '' ,
691
694
code : x . location + '' ,
695
+ dtype : 'int'
692
696
} ;
693
697
} ) ;
694
698
}
@@ -1012,7 +1016,7 @@ define([
1012
1016
return {
1013
1017
...x ,
1014
1018
value : x . label ,
1015
- code : x . value
1019
+ code : x . value ,
1016
1020
} ;
1017
1021
} ) ;
1018
1022
that . loadColumnList ( colList ) ;
@@ -1331,25 +1335,42 @@ define([
1331
1335
var thisTag = $ ( this ) ;
1332
1336
var varName = that . state . pandasObject ;
1333
1337
var colName = $ ( this ) . find ( 'option:selected' ) . attr ( 'data-code' ) ;
1338
+ var colDtype = $ ( this ) . find ( 'option:selected' ) . attr ( 'data-dtype' ) ;
1334
1339
1335
1340
var condTag = $ ( this ) . closest ( 'td' ) . find ( '.vp-condition' ) ;
1336
1341
1337
- // get result and load column list
1338
- vpKernel . getColumnCategory ( varName , colName ) . then ( function ( resultObj ) {
1339
- let { result } = resultObj ;
1340
- var category = JSON . parse ( result ) ;
1341
- if ( category && category . length > 0 ) {
1342
- // if it's categorical column, check 'Text' as default
1343
- $ ( thisTag ) . closest ( 'td' ) . find ( '.vp-cond-use-text' ) . prop ( 'checked' , true ) ;
1344
- } else {
1345
- $ ( thisTag ) . closest ( 'td' ) . find ( '.vp-cond-use-text' ) . prop ( 'checked' , false ) ;
1346
- }
1342
+ if ( colName == '.index' ) {
1343
+ // index
1344
+ $ ( thisTag ) . closest ( 'td' ) . find ( '.vp-cond-use-text' ) . prop ( 'checked' , false ) ;
1347
1345
$ ( condTag ) . replaceWith ( function ( ) {
1348
- return that . templateForConditionCondInput ( category ) ;
1346
+ return that . templateForConditionCondInput ( [ ] , '' ) ;
1349
1347
} ) ;
1350
1348
that . generateCode ( ) ;
1351
- } ) ;
1352
-
1349
+ } else {
1350
+ // get result and load column list
1351
+ vpKernel . getColumnCategory ( varName , colName ) . then ( function ( resultObj ) {
1352
+ let { result } = resultObj ;
1353
+ try {
1354
+ var category = JSON . parse ( result ) ;
1355
+ if ( category && category . length > 0 && colDtype == 'object' ) {
1356
+ // if it's categorical column and its dtype is object, check 'Text' as default
1357
+ $ ( thisTag ) . closest ( 'td' ) . find ( '.vp-cond-use-text' ) . prop ( 'checked' , true ) ;
1358
+ } else {
1359
+ $ ( thisTag ) . closest ( 'td' ) . find ( '.vp-cond-use-text' ) . prop ( 'checked' , false ) ;
1360
+ }
1361
+ $ ( condTag ) . replaceWith ( function ( ) {
1362
+ return that . templateForConditionCondInput ( category , colDtype ) ;
1363
+ } ) ;
1364
+ that . generateCode ( ) ;
1365
+ } catch {
1366
+ $ ( thisTag ) . closest ( 'td' ) . find ( '.vp-cond-use-text' ) . prop ( 'checked' , false ) ;
1367
+ $ ( condTag ) . replaceWith ( function ( ) {
1368
+ return that . templateForConditionCondInput ( [ ] , colDtype ) ;
1369
+ } ) ;
1370
+ that . generateCode ( ) ;
1371
+ }
1372
+ } ) ;
1373
+ }
1353
1374
} ) ;
1354
1375
1355
1376
// use text
@@ -1430,7 +1451,12 @@ define([
1430
1451
rowList . push ( rowValue ) ;
1431
1452
}
1432
1453
}
1433
- rowSelection . appendFormat ( '[{0}]' , rowList . toString ( ) ) ;
1454
+ if ( rowList . length == 1 ) {
1455
+ // to Series when rowList's length is 1.
1456
+ rowSelection . appendFormat ( '{0}' , rowList . toString ( ) ) ;
1457
+ } else {
1458
+ rowSelection . appendFormat ( '[{0}]' , rowList . toString ( ) ) ;
1459
+ }
1434
1460
} else {
1435
1461
rowSelection . append ( ':' ) ;
1436
1462
}
@@ -1465,43 +1491,55 @@ define([
1465
1491
rowSelection . append ( '(' ) ;
1466
1492
}
1467
1493
let colValue = colTag . find ( '.vp-col-list' ) . val ( ) ;
1468
- if ( colValue && colValue != '' ) {
1469
- if ( colValue == '.index' ) {
1470
- rowSelection . append ( 'index' ) ;
1471
- } else {
1472
- rowSelection . appendFormat ( '{0}' , colValue ) ;
1473
- }
1494
+ if ( colValue && colValue == '.index' ) {
1495
+ colValue = 'index' ;
1474
1496
}
1475
- oper && rowSelection . appendFormat ( ' {0}' , oper ) ;
1476
- if ( cond ) {
1477
- // condition value as text
1478
- if ( useText ) {
1479
- rowSelection . appendFormat ( " '{0}'" , cond ) ;
1480
- } else {
1481
- rowSelection . appendFormat ( " {0}" , cond ) ;
1482
- }
1497
+ let condValue = cond ;
1498
+ // condition value as text
1499
+ if ( cond && useText ) {
1500
+ condValue = com_util . formatString ( "'{0}'" , cond ) ;
1501
+ }
1502
+ if ( oper == 'contains' ) {
1503
+ rowSelection . appendFormat ( '{0}.str.contains({1})' , colValue , condValue ) ;
1504
+ } else if ( oper == 'not contains' ) {
1505
+ rowSelection . appendFormat ( '~{0}.str.contains({1})' , colValue , condValue ) ;
1506
+ } else if ( oper == 'starts with' ) {
1507
+ rowSelection . appendFormat ( '{0}.str.startswith({1})' , colValue , condValue ) ;
1508
+ } else if ( oper == 'ends with' ) {
1509
+ rowSelection . appendFormat ( '{0}.str.endswith({1})' , colValue , condValue ) ;
1510
+ } else {
1511
+ rowSelection . appendFormat ( '{0}{1}{2}' , colValue , oper != '' ?( ' ' + oper ) :'' , condValue != '' ?( ' ' + condValue ) :'' ) ;
1483
1512
}
1484
1513
if ( condList . length > 1 ) {
1485
1514
rowSelection . append ( ')' ) ;
1486
1515
}
1487
1516
} else {
1488
1517
if ( varType == 'DataFrame' ) {
1489
- rowSelection . appendFormat ( '({0}' , varName ) ;
1518
+ rowSelection . append ( '(' ) ;
1519
+
1520
+ let colValue = varName ;
1490
1521
if ( colName && colName != '' ) {
1491
1522
if ( colName == '.index' ) {
1492
- rowSelection . appendFormat ( '{0}' , colName ) ;
1523
+ colValue += colName ;
1493
1524
} else {
1494
- rowSelection . appendFormat ( '[{0}]' , colName ) ;
1525
+ colValue += com_util . formatString ( '[{0}]' , colName ) ;
1495
1526
}
1496
1527
}
1497
- oper && rowSelection . appendFormat ( ' {0}' , oper ) ;
1498
- if ( cond ) {
1499
- // condition value as text
1500
- if ( useText ) {
1501
- rowSelection . appendFormat ( " '{0}'" , cond ) ;
1502
- } else {
1503
- rowSelection . appendFormat ( " {0}" , cond ) ;
1504
- }
1528
+ let condValue = cond ;
1529
+ // condition value as text
1530
+ if ( cond && useText ) {
1531
+ condValue = com_util . formatString ( "'{0}'" , cond ) ;
1532
+ }
1533
+ if ( oper == 'contains' ) {
1534
+ rowSelection . appendFormat ( '{0}.str.contains({1})' , colValue , condValue ) ;
1535
+ } else if ( oper == 'not contains' ) {
1536
+ rowSelection . appendFormat ( '~{0}.str.contains({1})' , colValue , condValue ) ;
1537
+ } else if ( oper == 'starts with' ) {
1538
+ rowSelection . appendFormat ( '{0}.str.startswith({1})' , colValue , condValue ) ;
1539
+ } else if ( oper == 'ends with' ) {
1540
+ rowSelection . appendFormat ( '{0}.str.endswith({1})' , colValue , condValue ) ;
1541
+ } else {
1542
+ rowSelection . appendFormat ( '{0}{1}{2}' , colValue , oper != '' ?( ' ' + oper ) :'' , condValue != '' ?( ' ' + condValue ) :'' ) ;
1505
1543
}
1506
1544
rowSelection . append ( ')' ) ;
1507
1545
} else {
0 commit comments