Skip to content
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
2 changes: 1 addition & 1 deletion src/Tables/keywords/getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def read_table(
if self.file_type == FileType.Parquet and not self.ignore_header:
data.insert(0, list(table_df.columns))

if self.ignore_header and self.file_type != FileType.Parquet:
if self.ignore_header and self.file_type != FileType.Parquet and len(data) > 1:
table_df = table_df.iloc[1:]
data = data[1:]

Expand Down
4 changes: 3 additions & 1 deletion src/Tables/utils/file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ def validate_table_to_dataframe(
column = self.cast_column_type(column)
self.validate_column(data, column)

if self.file_type != FileType.Parquet and (isinstance(column, str) or self.ignore_header):
if self.file_type != FileType.Parquet and (
isinstance(column, str) or (self.ignore_header and len(data) > 1)
):
data.columns = data.iloc[0].to_list()
data = data[1:].reset_index(drop=True)
return data
Expand Down
31 changes: 31 additions & 0 deletions tests/atest/test_reader.robot
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*** Settings ***
Library Tables separator=,
Library OperatingSystem


*** Test Cases ***
Expand Down Expand Up @@ -162,6 +163,30 @@ CSV has No Headers - Open CSV Table and Not Ignore Header
${data} = Tables.Get Table
Length Should Be ${data} ${57}

Issue 45 - Keep Single Data Row When Ignoring Header
[Teardown] Reset Issue 45 Test File
VAR @{single_row} = 11:00:00 230.56
VAR @{table} = ${single_row}
${file_path} = Set Variable ${TEMPDIR}${/}tablelibrary_issue45.csv

Tables.Configure Ignore Header ${True}
Tables.Write Table ${table} ${file_path}
Tables.Open Table ${file_path}
${data} = Tables.Get Table
Length Should Be ${data} ${1}
Length Should Be ${data}[0] ${2}
Should Be Equal As Strings ${data}[0][0] 11:00:00
Should Be Equal As Strings ${data}[0][1] 230.56

Tables.Close Table
Tables.Configure Ignore Header ${False}
Tables.Open Table ${file_path}
${data} = Tables.Get Table
Length Should Be ${data} ${1}
Length Should Be ${data}[0] ${2}
Should Be Equal As Strings ${data}[0][0] 11:00:00
Should Be Equal As Strings ${data}[0][1] 230.56

########################################################################################
# TXT
########################################################################################
Expand Down Expand Up @@ -249,4 +274,10 @@ Read Row and Column Count - Parquet
Tables.Count Table ${parquet_path} Rows == ${1000}
Tables.Count Table ${parquet_path} Columns == ${2}

*** Keywords ***
Reset Issue 45 Test File
Tables.Close Table
Tables.Configure Ignore Header ${False}
Remove File ${TEMPDIR}${/}tablelibrary_issue45.csv


10 changes: 10 additions & 0 deletions tests/utest/keywords/test_keywords_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ def test_getter_ignore_header(getter, tmp_path, write_csv):
assert table == [ROW_1, ROW_2]


def test_getter_ignore_header_keeps_single_data_row(getter, tmp_path, write_csv):
path = tmp_path / "data.csv"
write_csv(path, [["11:00:00", 230.56]])
getter.library.scope_stack["ignore_header"].set(True)

getter.open_table(path, alias="t_single_row")

assert getter.get_table() == [["11:00:00", 230.56]]


def test_getter_invalid_assertion_operator(getter, tmp_path, write_csv):
path = tmp_path / "data.csv"
write_csv(path, ROWS)
Expand Down
Loading