Skip to content

Commit

Permalink
Preserve empty dataframe shape #321
Browse files Browse the repository at this point in the history
  • Loading branch information
xzkostyan committed Jul 1, 2022
1 parent b51d036 commit 4bc8a46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clickhouse_driver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,9 @@ def query_dataframe(
settings=settings
)

columns = [re.sub(r'\W', '_', name) for name, type_ in columns]
return pd.DataFrame(
{re.sub(r'\W', '_', col[0]): d for d, col in zip(data, columns)}
{col: d for d, col in zip(data, columns)}, columns=columns
)

def insert_dataframe(
Expand Down
7 changes: 7 additions & 0 deletions tests/numpy/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ def test_insert_not_ordered_columns(self):
)
self.assertEqual(rv, n)

def test_empty_frame_shape(self):
df = self.client.query_dataframe(
'SELECT number AS a, number AS a FROM system.numbers LIMIT 0'
)

self.assertEqual(df.shape, (0, 2))


class NoNumPyTestCase(BaseTestCase):
def setUp(self):
Expand Down

0 comments on commit 4bc8a46

Please sign in to comment.