GujaLomsadze commented on code in PR #50646:
URL: https://github.com/apache/arrow/pull/50646#discussion_r3681479630
##########
python/pyarrow/ipc.pxi:
##########
@@ -1192,6 +1192,39 @@ cdef class _RecordBatchFileReader(_Weakrefable):
"""
return self.reader.get().num_record_batches()
+ def count_rows(self):
+ """
+ The total number of rows in the IPC file.
+
+ This reads the metadata of each record batch in the file, without
+ deserializing the record batches themselves.
+
+ Returns
+ -------
+ count : int
+
+ Examples
+ --------
+ >>> import pyarrow as pa
+ >>> schema = pa.schema([('a', pa.int64())])
+ >>> sink = pa.BufferOutputStream()
+ >>> with pa.ipc.new_file(sink, schema) as writer:
+ ... for i in range(3):
+ ... writer.write_batch(pa.record_batch([[1, 2]],
schema=schema))
+ >>> with pa.ipc.open_file(sink.getvalue()) as reader:
+ ... reader.count_rows()
+ 6
+ """
+ cdef int64_t nrows
+
+ if not self.reader:
+ raise ValueError("Operation on closed reader")
+
Review Comment:
Good catch, removed. I copied it from the `stats` property, but that check
only makes sense on the stream reader, which has a `close()` that resets
`self.reader`. Check will never hit here, File reader has no close(). Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]