Skip to content

Commit b25d53b

Browse files
Address second round of review feedback
1 parent 5f128b1 commit b25d53b

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

examples/dataframe/create_write_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666
]
6767
client.append_table_data(table_id, batch_list)
6868

69-
# Flush only (no additional rows, mark end_of_data)
69+
# Mark end_of_data for the table
70+
# Supply `None` and `end_of_data=True`
7071
client.append_table_data(table_id, None, end_of_data=True)
71-
72-
# Empty iterable (must supply end_of_data)
72+
# OR supply an empty Iterable and `end_of_data=True`
7373
client.append_table_data(table_id, [], end_of_data=True)
7474
else:
7575
# If pyarrow not installed, flush via JSON path

nisystemlink/clients/dataframe/_data_frame_client.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,7 @@ def append_table_data(
359359
)
360360

361361
def _generate_body() -> Iterable[memoryview]:
362-
data_iter = iter(data)
363-
try:
364-
batch = next(data_iter)
365-
except StopIteration:
366-
return
362+
batch = first_batch
367363
with BytesIO() as buf:
368364
options = pa.ipc.IpcWriteOptions(compression="zstd")
369365
writer = pa.ipc.new_stream(buf, batch.schema, options=options)
@@ -374,14 +370,13 @@ def _generate_body() -> Iterable[memoryview]:
374370
yield slice
375371
buf.seek(0)
376372
try:
377-
batch = next(data_iter)
373+
batch = next(iterator)
378374
except StopIteration:
379375
break
380376

381377
writer.close()
382-
with buf.getbuffer() as view:
383-
with view[0 : buf.tell()] as slice:
384-
yield slice
378+
with buf.getbuffer() as view, view[0 : buf.tell()] as slice:
379+
yield slice
385380

386381
try:
387382
self._append_table_data_arrow(

tests/integration/dataframe/test_dataframe.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,10 @@ def test__append_table_data__flush_only_with_none(
684684
self, client: DataFrameClient, create_table
685685
):
686686
table_id = self._new_single_int_table(create_table)
687-
frame = DataFrame(columns=["a"], data=[["1"]])
688-
client.append_table_data(table_id, frame)
689687
client.append_table_data(table_id, None, end_of_data=True)
688+
metadata = client.get_table_metadata(table_id)
689+
assert metadata.row_count == 0
690+
assert metadata.supports_append is False
690691

691692
def test__append_table_data__arrow_ingestion_success(
692693
self, client: DataFrameClient, create_table
@@ -823,22 +824,14 @@ def test__append_table_data__arrow_ingestion_non_400_passthrough(
823824
self, client: DataFrameClient
824825
):
825826
pa = pytest.importorskip("pyarrow")
826-
table_id = "mock_table_id"
827827
batch = pa.record_batch([pa.array([1, 2, 3])], names=["a"])
828-
with responses.RequestsMock() as rsps:
829-
rsps.add(
830-
responses.POST,
831-
f"{client.session.base_url}tables/{table_id}/data",
832-
status=409,
833-
)
834-
with pytest.raises(ApiException) as excinfo:
835-
client.append_table_data(table_id, [batch], end_of_data=True)
828+
with pytest.raises(ApiException) as excinfo:
829+
client.append_table_data("111111111111111111111111", [batch], end_of_data=True)
836830
assert "Arrow ingestion request was rejected" not in str(excinfo.value)
837831

838832
def test__append_table_data__unsupported_type_raises(
839833
self, client: DataFrameClient, create_table
840834
):
841835
table_id = create_table(basic_table_model)
842836
with pytest.raises(ValueError, match="Unsupported type"):
843-
# cast to Any to satisfy type checker while still exercising runtime path
844-
client.append_table_data(table_id, cast(Any, 123))
837+
client.append_table_data(table_id, 123) # type: ignore[arg-type]

0 commit comments

Comments
 (0)