@@ -92,6 +92,7 @@ define([
92
92
useCopy : false ,
93
93
toFrame : false ,
94
94
subsetType : 'loc' , // subset / loc / iloc / query
95
+ returnType : '' ,
95
96
96
97
rowType : 'condition' ,
97
98
rowList : [ ] ,
@@ -197,7 +198,7 @@ define([
197
198
buttonTag . appendFormat ( '<button type="button" class="{0} {1} {2}">{3}</button>' ,
198
199
VP_DS_BTN , this . uuid , 'vp-button' , 'Subset' ) ;
199
200
if ( this . pageThis ) {
200
- $ ( this . targetSelector ) . parent ( ) . append ( buttonTag . toString ( ) ) ;
201
+ $ ( buttonTag . toString ( ) ) . insertAfter ( $ ( this . targetSelector ) ) ;
201
202
}
202
203
}
203
204
renderSubsetType ( dataType ) {
@@ -585,6 +586,7 @@ define([
585
586
renderColumnConditionList ( colList ) {
586
587
var tag = new com_String ( ) ;
587
588
tag . appendFormatLine ( '<table class="{0}">' , VP_DS_CONDITION_TBL ) ;
589
+ tag . appendLine ( this . templateForConditionBox ( colList ) ) ;
588
590
tag . appendLine ( '<tr>' ) ;
589
591
tag . appendFormatLine ( '<td colspan="4"><button type="button" class="{0} {1}">{2}</button></td>' ,
590
592
VP_DS_BUTTON_ADD_CONDITION , 'vp-add-col' , '+ Condition' ) ;
@@ -765,6 +767,7 @@ define([
765
767
var varType = JSON . parse ( result ) ;
766
768
that . state . pandasObject = prevValue ;
767
769
that . state . dataType = varType ;
770
+ that . state . returnType = varType ;
768
771
$ ( that . wrapSelector ( '.' + VP_DS_PANDAS_OBJECT_BOX ) ) . replaceWith ( function ( ) {
769
772
return $ ( com_util . formatString ( '<div style="display:inline-block"><input class="{0} {1}" value="{2}" disabled /></div>' ,
770
773
'vp-input' , VP_DS_PANDAS_OBJECT , prevValue ) ) ;
@@ -805,6 +808,7 @@ define([
805
808
$ ( this . wrapSelector ( ) ) . data ( 'dtype' , item . dtype ) ;
806
809
that . state . pandasObject = value ;
807
810
that . state . dataType = item . dtype ;
811
+ that . state . returnType = item . dtype ;
808
812
$ ( this . wrapSelector ( ) ) . trigger ( 'change' ) ;
809
813
} ) ;
810
814
variableInput . setNormalFilter ( true ) ;
@@ -1183,6 +1187,7 @@ define([
1183
1187
1184
1188
that . state . pandasObject = varName ;
1185
1189
that . state . dataType = event . dataType ? event . dataType : that . state . dataType ;
1190
+ that . state . returnType = that . state . dataType ;
1186
1191
that . state . rowList = [ ] ;
1187
1192
that . state . rowLimit = 10 ;
1188
1193
that . state . columnList = [ ] ;
@@ -1835,10 +1840,14 @@ define([
1835
1840
if ( this . state . colType == 'indexing' ) {
1836
1841
if ( this . useInputColumns == true ) {
1837
1842
colList = this . state . selectedColumns ;
1838
- if ( colList . length == 1 ) {
1839
- colSelection . appendFormat ( '{0}' , colList . toString ( ) ) ;
1840
- } else {
1841
- colSelection . appendFormat ( '[{0}]' , colList . toString ( ) ) ;
1843
+ if ( colList . length > 0 ) {
1844
+ if ( colList . length == 1 ) {
1845
+ colSelection . appendFormat ( '{0}' , colList . toString ( ) ) ;
1846
+ this . state . returnType = 'Series' ;
1847
+ } else {
1848
+ colSelection . appendFormat ( '[{0}]' , colList . toString ( ) ) ;
1849
+ this . state . returnType = 'DataFrame' ;
1850
+ }
1842
1851
}
1843
1852
} else {
1844
1853
var colTags = $ ( this . wrapSelector ( '.' + VP_DS_SELECT_ITEM + '.select-col.added:not(.moving)' ) ) ;
@@ -1858,11 +1867,14 @@ define([
1858
1867
// to frame
1859
1868
if ( this . state . toFrame ) {
1860
1869
colSelection . appendFormat ( '[{0}]' , colList . toString ( ) ) ;
1870
+ this . state . returnType = 'DataFrame' ;
1861
1871
} else {
1862
1872
colSelection . appendFormat ( '{0}' , colList . toString ( ) ) ;
1873
+ this . state . returnType = 'Series' ;
1863
1874
}
1864
1875
} else {
1865
1876
colSelection . appendFormat ( '[{0}]' , colList . toString ( ) ) ;
1877
+ this . state . returnType = 'DataFrame' ;
1866
1878
}
1867
1879
1868
1880
} else {
@@ -1877,31 +1889,34 @@ define([
1877
1889
}
1878
1890
1879
1891
// use simple selection
1880
- if ( this . state . subsetType == 'subset' ) {
1881
- if ( rowSelection . toString ( ) != ':' && rowSelection . toString ( ) != '' ) {
1882
- code . appendFormat ( '[{0}]' , rowSelection . toString ( ) ) ;
1883
- }
1884
- if ( colSelection . toString ( ) != ':' && colSelection . toString ( ) != '' ) {
1885
- code . appendFormat ( '[{0}]' , colSelection . toString ( ) ) ;
1886
- }
1887
- } else if ( this . state . subsetType == 'loc' ) {
1888
- if ( this . state . dataType == 'DataFrame' ) {
1889
- code . appendFormat ( '.loc[{0}, {1}]' , rowSelection . toString ( ) , colSelection . toString ( ) ) ;
1890
- } else {
1891
- code . appendFormat ( '.loc[{0}]' , rowSelection . toString ( ) ) ;
1892
- }
1893
- } else if ( this . state . subsetType == 'iloc' ) {
1894
- if ( this . state . dataType == 'DataFrame' ) {
1895
- code . appendFormat ( '.iloc[{0}, {1}]' , rowSelection . toString ( ) , colSelection . toString ( ) ) ;
1896
- } else {
1897
- code . appendFormat ( '.iloc[{0}]' , rowSelection . toString ( ) ) ;
1898
- }
1899
- } else if ( this . state . subsetType == 'query' ) {
1900
- if ( rowSelection . toString ( ) != ':' && rowSelection . toString ( ) != '' ) {
1901
- code . appendFormat ( '.query("{0}")' , rowSelection . toString ( ) ) ;
1902
- }
1903
- if ( colSelection . toString ( ) != ':' && colSelection . toString ( ) != '' ) {
1904
- code . appendFormat ( '[{0}]' , colSelection . toString ( ) ) ;
1892
+ if ( ( rowSelection . toString ( ) !== ':' && rowSelection . toString ( ) !== '' )
1893
+ || ( colSelection . toString ( ) !== ':' && colSelection . toString ( ) !== '' ) ) {
1894
+ if ( this . state . subsetType == 'subset' ) {
1895
+ if ( rowSelection . toString ( ) != ':' && rowSelection . toString ( ) != '' ) {
1896
+ code . appendFormat ( '[{0}]' , rowSelection . toString ( ) ) ;
1897
+ }
1898
+ if ( colSelection . toString ( ) != ':' && colSelection . toString ( ) != '' ) {
1899
+ code . appendFormat ( '[{0}]' , colSelection . toString ( ) ) ;
1900
+ }
1901
+ } else if ( this . state . subsetType == 'loc' ) {
1902
+ if ( this . state . dataType == 'DataFrame' ) {
1903
+ code . appendFormat ( '.loc[{0}, {1}]' , rowSelection . toString ( ) , colSelection . toString ( ) ) ;
1904
+ } else {
1905
+ code . appendFormat ( '.loc[{0}]' , rowSelection . toString ( ) ) ;
1906
+ }
1907
+ } else if ( this . state . subsetType == 'iloc' ) {
1908
+ if ( this . state . dataType == 'DataFrame' ) {
1909
+ code . appendFormat ( '.iloc[{0}, {1}]' , rowSelection . toString ( ) , colSelection . toString ( ) ) ;
1910
+ } else {
1911
+ code . appendFormat ( '.iloc[{0}]' , rowSelection . toString ( ) ) ;
1912
+ }
1913
+ } else if ( this . state . subsetType == 'query' ) {
1914
+ if ( rowSelection . toString ( ) != ':' && rowSelection . toString ( ) != '' ) {
1915
+ code . appendFormat ( '.query("{0}")' , rowSelection . toString ( ) ) ;
1916
+ }
1917
+ if ( colSelection . toString ( ) != ':' && colSelection . toString ( ) != '' ) {
1918
+ code . appendFormat ( '[{0}]' , colSelection . toString ( ) ) ;
1919
+ }
1905
1920
}
1906
1921
}
1907
1922
0 commit comments