Skip to content

Commit 538da46

Browse files
author
minjk-bl
committed
Change return structure of column and row list from dataframe
1 parent e2f8678 commit 538da46

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

visualpython/js/com/com_generator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,15 +583,15 @@ define([
583583
vpKernel.getColumnList(varName).then(function(resultObj) {
584584
try {
585585
let { result, type, msg } = resultObj;
586-
var varResult = JSON.parse(result);
586+
var { list } = JSON.parse(result);
587587

588588
// columns using suggestInput
589589
columnInputIdList && columnInputIdList.forEach(columnInputId => {
590590
var suggestInputX = new SuggestInput();
591591
suggestInputX.setComponentID(columnInputId);
592592
suggestInputX.addClass('vp-input vp-state');
593593
suggestInputX.setPlaceholder("column name");
594-
suggestInputX.setSuggestList(function() { return varResult; }); //FIXME:
594+
suggestInputX.setSuggestList(function() { return list; }); //FIXME:
595595
suggestInputX.setNormalFilter(false);
596596
suggestInputX.setValue($(selector + ' #' + columnInputId).val());
597597
$(selector + ' #' + columnInputId).replaceWith(function() {

visualpython/js/com/com_generatorV2.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ define([
861861
vpKernel.getColumnList(varName).then(function(resultObj) {
862862
try {
863863
let { result, type, msg } = resultObj;
864-
var varResult = JSON.parse(result);
864+
var { list } = JSON.parse(result);
865865

866866
// check if it needs to add index option
867867
let addIndex = false;
@@ -871,9 +871,9 @@ define([
871871
addIndex = columnWithIndex;
872872
}
873873
if (addIndex == true) {
874-
varResult = [
874+
list = [
875875
{value: varName + '.index', label: 'index'},
876-
...varResult
876+
...list
877877
]
878878
}
879879

@@ -885,9 +885,9 @@ define([
885885
addEmpty = columnWithEmpty;
886886
}
887887
if (addEmpty == true) {
888-
varResult = [
888+
list = [
889889
{value: '', label: 'Select option...'},
890-
...varResult
890+
...list
891891
]
892892
}
893893

@@ -903,7 +903,7 @@ define([
903903
suggestInputX.setComponentID(columnInputId);
904904
suggestInputX.addClass('vp-input vp-state');
905905
suggestInputX.setPlaceholder("column name");
906-
suggestInputX.setSuggestList(function() { return varResult; }); //FIXME:
906+
suggestInputX.setSuggestList(function() { return list; }); //FIXME:
907907
suggestInputX.setNormalFilter(false);
908908
suggestInputX.setValue(defaultValue);
909909
$(selector + ' #' + columnInputId).replaceWith(function() {

visualpython/js/com/component/MultiSelector.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,16 @@ define([
168168
vpKernel.getColumnList(parent).then(function(resultObj) {
169169
let { result } = resultObj;
170170
try {
171-
var colList = JSON.parse(result);
172-
colList = colList.map(function(x) {
171+
var { list } = JSON.parse(result);
172+
list = list.map(function(x) {
173173
return {
174174
...x,
175175
value: x.label,
176176
code: x.value,
177177
type: x.dtype
178178
};
179179
});
180-
callback(colList);
180+
callback(list);
181181
} catch (e) {
182182
callback([]);
183183
}
@@ -189,7 +189,7 @@ define([
189189
vpKernel.getRowList(parent).then(function(resultObj) {
190190
let { result } = resultObj;
191191
try {
192-
var rowList = JSON.parse(result);
192+
var { list:rowList } = JSON.parse(result);
193193
rowList = rowList.map(function(x) {
194194
return {
195195
...x,

visualpython/js/com/component/VarSelector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,15 @@ define([
239239
vpKernel.getColumnList(varName).then(function(resultObj) {
240240
try {
241241
let { result, type, msg } = resultObj;
242-
var varResult = JSON.parse(result);
242+
var { list } = JSON.parse(result);
243243

244244
let newTag = new com_String();
245245
newTag.appendFormatLine('<select class="{0} {1} {2}" {3}>',
246246
VP_VS_COLUMN_INPUT, 'vp-select m', that.colClass.join(' '),
247247
(that.useColumn == true && that.defaultType == 'DataFrame'?'':'style="display: none;"'));
248248
newTag.appendFormatLine('<option value="{0}" data-dtype="{1}">{2}</option>',
249249
'', '', '');
250-
varResult && varResult.forEach(col => {
250+
list && list.forEach(col => {
251251
// label, value, dtype, array, location, category
252252
newTag.appendFormatLine('<option value="{0}" data-dtype="{1}" {2}>{3}</option>',
253253
col.value, col.dtype,

visualpython/js/m_apps/Subset.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ define([
324324
let subsetVariable = com_util.formatString('{0}.iloc[{1}:{2}]', that.state.pandasObject, start, end);
325325
vpKernel.getRowList(subsetVariable).then(function (resultObj) {
326326
let { result } = resultObj;
327-
var rowList = JSON.parse(result);
327+
var { list:rowList } = JSON.parse(result);
328328
rowList = rowList.map(function (x) {
329329
return {
330330
...x,
@@ -1179,15 +1179,15 @@ define([
11791179
// get result and load column list
11801180
vpKernel.getColumnList(varName).then(function (resultObj) {
11811181
let { result } = resultObj;
1182-
var colList = JSON.parse(result);
1183-
colList = colList.map(function (x) {
1182+
var { list } = JSON.parse(result);
1183+
list = list.map(function (x) {
11841184
return {
11851185
...x,
11861186
value: x.label,
11871187
code: x.value,
11881188
};
11891189
});
1190-
that.loadColumnList(colList);
1190+
that.loadColumnList(list);
11911191
that.bindDraggable('col');
11921192
that.generateCode();
11931193
});
@@ -1196,7 +1196,7 @@ define([
11961196
let subsetVariable = com_util.formatString('{0}.iloc[:{1}]', varName, that.state.rowLimit);
11971197
vpKernel.getRowList(subsetVariable).then(function (resultObj) {
11981198
let { result } = resultObj;
1199-
var rowList = JSON.parse(result);
1199+
var { list:rowList } = JSON.parse(result);
12001200
rowList = rowList.map(function (x) {
12011201
return {
12021202
...x,
@@ -1229,7 +1229,7 @@ define([
12291229
let subsetVariable = com_util.formatString('{0}.iloc[:{1}]', varName, that.state.rowLimit);
12301230
vpKernel.getRowList(subsetVariable).then(function (resultObj) {
12311231
let { result } = resultObj;
1232-
var rowList = JSON.parse(result);
1232+
var { list:rowList } = JSON.parse(result);
12331233
rowList = rowList.map(function (x) {
12341234
return {
12351235
...x,

visualpython/python/pandasCommand.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def _vp_get_rows_list(df):
1515
"""
1616
Get Rows List with Detail Information
1717
"""
18-
rowList = []
18+
rowInfo = { 'name': df.index.name, 'level': df.index.nlevels, 'list': [] }
1919
indexType = str(df.index.dtype)
2020
# make dict for rows info
2121
for i, r in enumerate(df.index):
@@ -28,18 +28,21 @@ def _vp_get_rows_list(df):
2828
rInfo['label'] = str(r)
2929
rInfo['value'] = "'{}'".format(r)
3030
rInfo['index_dtype'] = indexType # datetime64[ns] TODO: exception consideration needed
31-
rowList.append(rInfo)
32-
return rowList
31+
rowInfo['list'].append(rInfo)
32+
return rowInfo
3333

3434
def _vp_get_columns_list(df):
3535
"""
3636
Get Columns List with Detail Information
3737
"""
38-
colList = []
38+
colInfo = { 'name': list(df.columns.names), 'level': df.columns.nlevels, 'list': [] }
3939
for i, c in enumerate(df.columns):
4040
cInfo = { 'label': c, 'value': c, 'dtype': str(df[c].dtype), 'array': str(df[c].array), 'location': i }
4141
# value
42-
if type(c).__name__ == 'str':
42+
if type(c).__name__ == 'list' or type(c).__name__ == 'tuple':
43+
cInfo['label'] = list(c)
44+
cInfo['value'] = ["'{}'".format(ci) if type(ci).__name__ == 'str' else str(ci) if type(ci).__name__ == 'Timestamp' else ci for ci in c]
45+
elif type(c).__name__ == 'str':
4346
cInfo['value'] = "'{}'".format(c)
4447
elif type(c).__name__ == 'Timestamp':
4548
cInfo['value'] = str(c)
@@ -52,8 +55,8 @@ def _vp_get_columns_list(df):
5255
cInfo['category'] = []
5356
else:
5457
cInfo['category'] = []
55-
colList.append(cInfo)
56-
return colList
58+
colInfo['list'].append(cInfo)
59+
return colInfo
5760

5861
def _vp_get_multi_columns_list(dfs = []):
5962
"""

0 commit comments

Comments
 (0)