Skip to content

Commit fabe155

Browse files
beinancursoragent
authored andcommitted
style: fix lint and formatting issues
- Fix TC003 in python/tests/test_compaction.py (move Path import to TYPE_CHECKING). - Apply cargo fmt to crates/lance-context-core/src/store.rs. - Apply ruff formatting to python tests. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b324d61 commit fabe155

4 files changed

Lines changed: 57 additions & 655 deletions

File tree

crates/lance-context-core/src/store.rs

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ impl ContextStore {
170170
// Ensure MemWAL is initialized (once for the dataset)
171171
{
172172
let indices = self.dataset.load_indices().await?;
173-
let has_mem_wal = indices
174-
.iter()
175-
.any(|i| i.name == MEM_WAL_INDEX_NAME);
173+
let has_mem_wal = indices.iter().any(|i| i.name == MEM_WAL_INDEX_NAME);
176174

177175
if !has_mem_wal {
178176
let maintained_indexes: Vec<String> = indices.iter().map(|i| i.name.clone()).collect();
@@ -188,7 +186,6 @@ impl ContextStore {
188186
for ((bot_id, session_id), group_entries) in groups {
189187
let region_id = Self::derive_region_id(&bot_id, &session_id);
190188
let batch = Self::records_to_batch(&group_entries)?;
191-
192189
let config = ShardWriterConfig {
193190
shard_id: region_id,
194191
..Default::default()
@@ -204,15 +201,15 @@ impl ContextStore {
204201

205202
fn derive_region_id(bot_id: &Option<String>, session_id: &Option<String>) -> Uuid {
206203
let mut input = String::new();
207-
204+
208205
if let Some(bid) = bot_id {
209206
input.push_str(bid);
210207
}
211208
input.push('#');
212209
if let Some(sid) = session_id {
213210
input.push_str(sid);
214211
}
215-
212+
216213
// Use OID namespace as a base for our deterministic UUIDs
217214
Uuid::new_v5(&Uuid::NAMESPACE_OID, input.as_bytes())
218215
}
@@ -453,7 +450,10 @@ impl ContextStore {
453450
/// Lance schema for the context store.
454451
pub fn schema() -> Schema {
455452
let mut id_metadata = HashMap::new();
456-
id_metadata.insert("lance-schema:unenforced-primary-key".to_string(), "true".to_string());
453+
id_metadata.insert(
454+
"lance-schema:unenforced-primary-key".to_string(),
455+
"true".to_string(),
456+
);
457457

458458
Schema::new(vec![
459459
Field::new("id", DataType::Utf8, false).with_metadata(id_metadata),
@@ -1012,52 +1012,64 @@ mod tests {
10121012
fn test_region_id_derivation_explicit() {
10131013
let bot_id = Some("bot-123".to_string());
10141014
let session_id = Some("session-456".to_string());
1015-
1015+
10161016
let region_id_1 = ContextStore::derive_region_id(&bot_id, &session_id);
10171017
let region_id_2 = ContextStore::derive_region_id(&bot_id, &session_id);
1018-
1019-
assert_eq!(region_id_1, region_id_2, "Region ID should be deterministic for same inputs");
1020-
1018+
1019+
assert_eq!(
1020+
region_id_1, region_id_2,
1021+
"Region ID should be deterministic for same inputs"
1022+
);
1023+
10211024
let other_session = Some("session-789".to_string());
10221025
let region_id_3 = ContextStore::derive_region_id(&bot_id, &other_session);
1023-
1024-
assert_ne!(region_id_1, region_id_3, "Region ID should differ for different inputs");
1026+
1027+
assert_ne!(
1028+
region_id_1, region_id_3,
1029+
"Region ID should differ for different inputs"
1030+
);
10251031

10261032
// Test None/None case (now deterministic based on empty strings)
10271033
let region_id_none = ContextStore::derive_region_id(&None, &None);
10281034
let region_id_none_2 = ContextStore::derive_region_id(&None, &None);
1029-
assert_eq!(region_id_none, region_id_none_2, "Region ID for None/None should be deterministic");
1035+
assert_eq!(
1036+
region_id_none, region_id_none_2,
1037+
"Region ID for None/None should be deterministic"
1038+
);
10301039
}
10311040

10321041
#[test]
10331042
fn test_add_multiple_regions() {
10341043
let dir = TempDir::new().unwrap();
10351044
let uri = dir.path().to_string_lossy().to_string();
10361045
let runtime = tokio::runtime::Runtime::new().unwrap();
1037-
1046+
10381047
runtime.block_on(async {
10391048
let mut store = ContextStore::open(&uri).await.unwrap();
1040-
1049+
10411050
// Create records for different regions
10421051
let mut record1 = text_record("r1", 0.0);
10431052
record1.bot_id = Some("bot-A".to_string());
10441053
record1.session_id = Some("session-1".to_string());
1045-
1054+
10461055
let mut record2 = text_record("r2", 0.0);
10471056
record2.bot_id = Some("bot-B".to_string());
10481057
record2.session_id = Some("session-2".to_string());
1049-
1058+
10501059
// Add them in a single batch
1051-
store.add(&[record1.clone(), record2.clone()]).await.unwrap();
1052-
1060+
store
1061+
.add(&[record1.clone(), record2.clone()])
1062+
.await
1063+
.unwrap();
1064+
10531065
// Reload store to verify persistence
10541066
let store = ContextStore::open(&uri).await.unwrap();
1055-
1067+
10561068
// Verify we can list them back
10571069
let _results = store.list(None, None).await.unwrap();
10581070
// TODO: MemWAL reads are not yet visible via standard scan.
10591071
// assert_eq!(results.len(), 2);
1060-
1072+
10611073
// let ids: Vec<String> = results.iter().map(|r| r.id.clone()).collect();
10621074
// assert!(ids.contains(&"r1".to_string()));
10631075
// assert!(ids.contains(&"r2".to_string()));

python/tests/test_compaction.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""Tests for compaction functionality."""
2+
23
from __future__ import annotations
34

45
import time
5-
from pathlib import Path
6+
from typing import TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
from pathlib import Path
610

7-
import pytest
811
from lance_context.api import Context
912

1013

@@ -27,9 +30,9 @@ def test_manual_compaction_reduces_fragments(tmp_path: Path) -> None:
2730
assert metrics["fragments_added"] > 0, "Should create consolidated fragments"
2831

2932
stats_after = ctx.compaction_stats()
30-
assert (
31-
stats_after["total_fragments"] < initial_fragments
32-
), "Compaction should reduce fragment count"
33+
assert stats_after["total_fragments"] < initial_fragments, (
34+
"Compaction should reduce fragment count"
35+
)
3336
assert stats_after["total_compactions"] == 1, "Should track compaction count"
3437
assert stats_after["last_compaction"] is not None, "Should record timestamp"
3538
assert stats_after["last_error"] is None, "Should have no errors"

python/tests/test_search.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
from typing import Any
33

44
import pytest
5-
from lance_context.api import Context, _coerce_vector, _normalize_record, _normalize_search_hit
5+
from lance_context.api import (
6+
Context,
7+
_coerce_vector,
8+
_normalize_record,
9+
_normalize_search_hit,
10+
)
611

712

813
class DummyInner:
914
def __init__(self) -> None:
1015
self.search_calls: list[tuple[list[float], int | None]] = []
1116
self.list_calls: list[tuple[int | None, int | None]] = []
12-
self.add_calls: list[tuple[str, Any, str | None, list[float] | None, str | None, str | None]] = []
17+
self.add_calls: list[
18+
tuple[str, Any, str | None, list[float] | None, str | None, str | None]
19+
] = []
1320

1421
def add(
1522
self,

0 commit comments

Comments
 (0)