Skip to content

Commit f778c10

Browse files
committed
changed the column selection query to handle invalid file error
1 parent 4ed3035 commit f778c10

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

  • digital_land/expectations/operations

digital_land/expectations/operations/csv.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ def _read_csv(file_path: Path) -> str:
1313

1414

1515
def _get_csv_columns(conn, file_path: Path) -> list:
16-
"""Get column names from CSV file."""
17-
return [
18-
col[0]
19-
for col in conn.execute(
20-
f"SELECT * FROM {_read_csv(file_path)} LIMIT 0"
21-
).description
22-
]
16+
result = conn.execute(
17+
"DESCRIBE SELECT * FROM read_csv_auto(?)", [str(file_path)]
18+
).fetchall()
19+
return [row[0] for row in result]
2320

2421

2522
def _sql_string(value) -> str:

0 commit comments

Comments
 (0)