Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep column order in .csv #2377

Merged
merged 1 commit into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions superset/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def data(self):
return self.__df.to_dict(orient='records')

@property
def columns_dict(self):
def columns(self):
"""Provides metadata about columns for data visualization.

:return: dict, with the fields name, type, is_date, is_dim and agg.
Expand Down Expand Up @@ -69,7 +69,6 @@ def columns_dict(self):
if not column['agg']:
column.pop('agg', None)
columns.append(column)

return columns


Expand Down
2 changes: 1 addition & 1 deletion superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def handle_error(msg):
'query_id': query.id,
'status': query.status,
'data': cdf.data if cdf.data else [],
'columns': cdf.columns_dict if cdf.columns_dict else {},
'columns': cdf.columns if cdf.columns else [],
'query': query.to_dict(),
}
payload = json.dumps(payload, default=utils.json_iso_dttm_ser)
Expand Down
3 changes: 2 additions & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,8 @@ def csv(self, client_id):
if blob:
json_payload = zlib.decompress(blob)
obj = json.loads(json_payload)
df = pd.DataFrame.from_records(obj['data'])
columns = [c['name'] for c in obj['columns']]
df = pd.DataFrame.from_records(obj['data'], columns=columns)
csv = df.to_csv(index=False, encoding='utf-8')
else:
sql = query.select_sql or query.executed_sql
Expand Down
10 changes: 5 additions & 5 deletions tests/celery_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_run_sync_query_cta(self):
db_id, sql_where, "2", tmp_table='tmp_table_2', cta='true')
self.assertEqual(QueryStatus.SUCCESS, result2['query']['state'])
self.assertEqual([], result2['data'])
self.assertEqual({}, result2['columns'])
self.assertEqual([], result2['columns'])
query2 = self.get_query_by_id(result2['query']['serverId'])

# Check the data in the tmp table.
Expand All @@ -204,7 +204,7 @@ def test_run_sync_query_cta_no_data(self):
db_id, sql_empty_result, "3", tmp_table='tmp_table_3', cta='true')
self.assertEqual(QueryStatus.SUCCESS, result3['query']['state'])
self.assertEqual([], result3['data'])
self.assertEqual({}, result3['columns'])
self.assertEqual([], result3['columns'])

query3 = self.get_query_by_id(result3['query']['serverId'])
self.assertEqual(QueryStatus.SUCCESS, query3.status)
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_run_async_query(self):
self.assertEqual(True, query.select_as_cta)
self.assertEqual(True, query.select_as_cta_used)

def test_get_columns_dict(self):
def test_get_columns(self):
main_db = self.get_main_database(db.session)
df = main_db.get_df("SELECT * FROM multiformat_time_series", None)
cdf = dataframe.SupersetDataFrame(df)
Expand All @@ -260,7 +260,7 @@ def test_get_columns_dict(self):
'is_dim': False},
{'is_date': False, 'type': 'object',
'name': 'string3', 'is_dim': True}]
, cdf.columns_dict
, cdf.columns
)
else:
self.assertEqual(
Expand All @@ -280,7 +280,7 @@ def test_get_columns_dict(self):
'is_dim': False},
{'is_date': False, 'type': 'object',
'name': 'string3', 'is_dim': True}]
, cdf.columns_dict
, cdf.columns
)


Expand Down