Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Wrapper: Fix reader iteration #7139

Merged
merged 1 commit into from
Dec 10, 2023
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
5 changes: 4 additions & 1 deletion clients/python-wrapper/lakefs/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def writelines(self, lines: List[AnyStr]) -> None:
raise io.UnsupportedOperation

def __next__(self) -> AnyStr:
return self.readline()
line = self.readline()
if len(line) == 0:
raise StopIteration
return line

def __iter__(self) -> Iterator[AnyStr]:
return self
Expand Down
23 changes: 23 additions & 0 deletions clients/python-wrapper/tests/integration/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,26 @@ def test_readline_partial_line_buffer(setup_repo):
assert read == expected

assert reader.read() == ""


def test_write_read_csv(setup_repo):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

_, repo = setup_repo
columns = ["ID", "Name", "Email"]
sample_data = [
['1', "Alice", "[email protected]"],
['2', "Bob", "[email protected]"],
['3', "Carol", "[email protected]"],
]
obj = repo.branch("main").object(path="csv/sample_data.csv")

with obj.writer(mode='w', pre_sign=False, content_type="text/csv") as fd:
writer = csv.writer(fd)
writer.writerow(columns)
for row in sample_data:
writer.writerow(row)

for i, row in enumerate(csv.reader(obj.reader(mode='r'))):
if i == 0:
assert row == columns
else:
assert row == sample_data[i - 1]
Loading