Skip to content

Commit 6ce0bb1

Browse files
committed
feat: use header option.
1 parent a956d4f commit 6ce0bb1

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

turu-snowflake/src/turu/snowflake/record/record_cursor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ def fetch_pandas_all(self, **kwargs) -> "PandasDataFrame":
88

99
if isinstance(self._recorder, turu.core.record.CsvRecorder):
1010
if limit := self._recorder._options.get("limit"):
11-
df.head(limit).to_csv(self._recorder.file, index=False)
11+
record_df = df.head(limit)
1212

1313
else:
14-
df.to_csv(self._recorder.file, index=False)
14+
record_df = df
15+
16+
record_df.to_csv(
17+
self._recorder.file,
18+
index=False,
19+
header=self._recorder._options.get("header", True),
20+
)
1521

1622
return df

turu-snowflake/tests/turu/test_snowflake.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,35 @@ def test_record_pandas_dataframe(self, connection: turu.snowflake.Connection):
266266
).lstrip()
267267
)
268268

269+
@pytest.mark.skipif(not USE_PANDAS, reason="pandas is not installed")
270+
def test_record_pandas_dataframe_without_header_option(
271+
self, connection: turu.snowflake.Connection
272+
):
273+
import pandas as pd # type: ignore[import]
274+
from pandas.testing import assert_frame_equal # type: ignore[import]
275+
276+
with tempfile.NamedTemporaryFile() as file:
277+
with record_to_csv(
278+
file.name,
279+
connection.execute_map(
280+
pd.DataFrame, "select 1 as ID union all select 2 AS ID"
281+
),
282+
header=False,
283+
) as cursor:
284+
expected = pd.DataFrame({"ID": [1, 2]}, dtype="int8")
285+
286+
assert_frame_equal(cursor.fetch_pandas_all(), expected)
287+
288+
assert (
289+
Path(file.name).read_text()
290+
== dedent(
291+
"""
292+
1
293+
2
294+
"""
295+
).lstrip()
296+
)
297+
269298
@pytest.mark.skipif(not USE_PANDAS, reason="pandas is not installed")
270299
def test_record_pandas_dataframe_with_limit_option(
271300
self, connection: turu.snowflake.Connection

0 commit comments

Comments
 (0)