Skip to content

Commit c42f00e

Browse files
authored
Check for Empty DF & Include Column Names (#145)
Closes #144
1 parent 129958a commit c42f00e

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/sources/dune.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ def dune_result_to_df(result: ExecutionResult) -> TypedDataFrame:
225225
varbinary_cols.extend(_varbinary_cols)
226226
unknown_cols.extend(_unknown_cols)
227227

228-
df = pd.DataFrame(result.rows)
228+
df = pd.DataFrame(result.rows, columns=metadata.column_names)
229+
if df.empty:
230+
return TypedDataFrame(df, dtypes)
231+
229232
df = _reformat_varbinary_columns(df, varbinary_cols)
230233
df = _reformat_unknown_columns(df, unknown_cols)
231234

tests/e2e_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@
4747
],
4848
"metadata": {
4949
"column_names": [
50-
"blocktime",
50+
"block_date",
5151
"block_number",
52-
"success",
52+
"blocktime",
5353
"hash",
54+
"success",
5455
"type",
55-
"block_date",
5656
"some_number",
5757
],
5858
"column_types": [
59-
"timestamp with time zone",
59+
"date",
6060
"bigint",
61-
"boolean",
61+
"timestamp with time zone",
6262
"varbinary",
63+
"boolean",
6364
"varchar",
64-
"date",
6565
"decimal(12, 7)",
6666
],
6767
"row_count": 1,
@@ -133,6 +133,7 @@ def test_dune_results_to_db(self):
133133
"some_number": [12.001],
134134
}
135135
)
136+
print(expected)
136137
self.assertIsNone(
137138
pandas.testing.assert_frame_equal(df, expected, check_dtype=True)
138139
)

0 commit comments

Comments
 (0)