This commit is contained in:
ikatyal2110 2026-07-21 09:31:54 -05:00 committed by GitHub
commit 1d68563356
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -379,6 +379,8 @@ def rows_from_file(
raise TypeError(
"rows_from_file() requires a file-like object that supports peek(), such as io.BytesIO"
)
if not first_bytes:
return iter([]), Format.CSV
if first_bytes.startswith(b"[") or first_bytes.startswith(b"{"):
# TODO: Detect newline-JSON
return rows_from_file(buffered, format=Format.JSON)

View file

@ -52,3 +52,10 @@ def test_rows_from_file_error_on_string_io():
assert ex.value.args == (
"rows_from_file() requires a file-like object that supports peek(), such as io.BytesIO",
)
@pytest.mark.parametrize("content", [b"", b" \n\n "])
def test_rows_from_file_empty_file(content):
rows, fmt = rows_from_file(BytesIO(content))
assert list(rows) == []
assert fmt == Format.CSV