Skip to content
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
4 changes: 4 additions & 0 deletions python/python/lance/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ def read_global_buffer(self, index: int) -> bytes:
"""
return self._reader.read_global_buffer(index)

def num_rows(self) -> int:
"""Return the number of rows belonging to the data file."""
return self._reader.num_rows()


class LanceFileWriter:
"""
Expand Down
1 change: 1 addition & 0 deletions python/python/lance/lance/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class LanceFileReader:
def read_global_buffer(self, index: int) -> bytes: ...
def metadata(self) -> LanceFileMetadata: ...
def file_statistics(self) -> LanceFileStatistics: ...
def num_rows(self): ...

class LanceBufferDescriptor:
position: int
Expand Down
11 changes: 11 additions & 0 deletions python/python/tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ def test_take(tmp_path):
assert table == pa.table({"a": [0, 77, 83]})


def test_num_rows(tmp_path):
path = tmp_path / "foo.lance"
schema = pa.schema([pa.field("a", pa.int64())])
writer = LanceFileWriter(str(path), schema)
writer.write_batch(pa.table({"a": [i for i in range(100)]}))
writer.close()

reader = LanceFileReader(str(path))
assert reader.num_rows() == 100


def check_round_trip(tmp_path, table):
path = tmp_path / "foo.lance"
with LanceFileWriter(str(path), table.schema) as writer:
Expand Down
4 changes: 4 additions & 0 deletions python/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ impl LanceFileReader {
.infer_error()?;
Ok(buffer_bytes.to_vec())
}

pub fn num_rows(&mut self) -> u64 {
self.inner.num_rows()
}
}

#[cfg(test)]
Expand Down
Loading