Skip to content

Commit 923686d

Browse files
tonyyang-svailYancey0623
authored andcommitted
Add to_dataframe and better data presentation (#86)
* Add to_dataframe and better data presentation * update deps
1 parent 78ea02e commit 923686d

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'protobuf >=3.6, <4',
2121
'grpcio >=1.17, <2',
2222
'ipython>=1.0',
23-
'prettytable',
23+
'pandas',
2424
]
2525
SETUP_REQUIRED = [
2626
'pytest-runner'

sqlflow/rows.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
class Rows:
42
def __init__(self, column_names, rows_gen):
53
"""Query result of sqlflow.client.Client.execute
@@ -42,15 +40,19 @@ def __str__(self):
4240
return self.__repr__()
4341

4442
def __repr__(self):
45-
from prettytable import PrettyTable
46-
table = PrettyTable(self._column_names)
47-
for row in self.rows():
48-
table.add_row(row)
49-
return table.__str__()
43+
return self.to_dataframe().__repr__()
44+
45+
def _repr_html_(self):
46+
return self.to_dataframe()._repr_html_()
5047

5148
def to_dataframe(self):
5249
"""Convert Rows to pandas.Dataframe
5350
5451
:return: pandas.Dataframe
5552
"""
56-
raise NotImplementedError
53+
# Fetch all the rows to self._rows
54+
for r in self.rows():
55+
pass
56+
import pandas as pd
57+
return pd.DataFrame(self._rows, columns=self._column_names)
58+

0 commit comments

Comments
 (0)