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
2 changes: 1 addition & 1 deletion python/python/lance/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def from_json(json_data: str) -> FragmentMetadata:

row_id_meta = json_data.get("row_id_meta")
if row_id_meta is not None:
row_id_meta = RowIdMeta(**row_id_meta)
row_id_meta = RowIdMeta.from_dict(row_id_meta)

created_at_version_meta = json_data.get("created_at_version_meta")
if created_at_version_meta is not None:
Expand Down
9 changes: 8 additions & 1 deletion python/python/tests/test_fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,16 @@ def test_fragment_metadata_pickle(tmp_path: Path, enable_stable_row_ids: bool):

# Pickle and unpickle the fragment metadata
round_trip = pickle.loads(pickle.dumps(frag_meta))

assert frag_meta == round_trip

# JSON round-trip
json_data = frag_meta.to_json()
json_round_trip = FragmentMetadata.from_json(json.dumps(json_data))
assert frag_meta.id == json_round_trip.id
assert frag_meta.physical_rows == json_round_trip.physical_rows
if enable_stable_row_ids:
assert json_round_trip.row_id_meta is not None


def test_deletion_file_with_base_id_serialization():
"""Test that DeletionFile with base_id serializes correctly."""
Expand Down
15 changes: 11 additions & 4 deletions python/src/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,10 @@ pub struct PyRowDatasetVersionMeta(pub RowDatasetVersionMeta);

#[pymethods]
impl PyRowIdMeta {
fn asdict(&self) -> PyResult<Bound<'_, PyDict>> {
Err(PyNotImplementedError::new_err(
"PyRowIdMeta.asdict is not yet supported.s",
))
fn asdict(&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
pythonize::pythonize(py, &self.0)
.map(|b| b.unbind())
.map_err(|err| PyValueError::new_err(format!("Could not convert RowIdMeta: {}", err)))
}

pub fn json(&self) -> PyResult<String> {
Expand All @@ -650,6 +650,13 @@ impl PyRowIdMeta {
Ok(Self(row_id_meta))
}

#[staticmethod]
pub fn from_dict(dict: &Bound<'_, PyAny>) -> PyResult<Self> {
let row_id_meta: RowIdMeta = pythonize::depythonize(dict)
.map_err(|err| PyValueError::new_err(format!("Could not load RowIdMeta: {}", err)))?;
Ok(Self(row_id_meta))
}

fn __reduce__(&self, py: Python<'_>) -> PyResult<(Py<PyAny>, Py<PyAny>)> {
let state = self.json()?;
let state = PyTuple::new(py, vec![state])?.extract()?;
Expand Down
Loading