From d5a01ffe7b2e8ef23d2cfeb489417da7db3b723e Mon Sep 17 00:00:00 2001 From: Gagan Bhullar Date: Wed, 7 Aug 2024 09:46:46 -0600 Subject: [PATCH] feat(python): index config repr method (#1509) PR fixes #1506 --- python/python/tests/test_index.py | 1 + python/src/index.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/python/python/tests/test_index.py b/python/python/tests/test_index.py index 75917894..8e5a4053 100644 --- a/python/python/tests/test_index.py +++ b/python/python/tests/test_index.py @@ -42,6 +42,7 @@ async def test_create_scalar_index(some_table: AsyncTable): # Can recreate if replace=True await some_table.create_index("id", replace=True) indices = await some_table.list_indices() + assert str(indices) == '[Index(BTree, columns=["id"])]' assert len(indices) == 1 assert indices[0].index_type == "BTree" assert indices[0].columns == ["id"] diff --git a/python/src/index.rs b/python/src/index.rs index 494ab707..d10524a0 100644 --- a/python/src/index.rs +++ b/python/src/index.rs @@ -98,6 +98,13 @@ pub struct IndexConfig { pub columns: Vec, } +#[pymethods] +impl IndexConfig { + pub fn __repr__(&self) -> String { + format!("Index({}, columns={:?})", self.index_type, self.columns) + } +} + impl From for IndexConfig { fn from(value: lancedb::index::IndexConfig) -> Self { let index_type = format!("{:?}", value.index_type);