Skip to content

Commit b6ee6ad

Browse files
committed
Refactor neuron part tests to set minimum expected count and improve cache key handling for DataFrame results
1 parent fa6a806 commit b6ee6ad

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

src/test/test_neurons_part_here.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def setUp(self):
1515
"""Set up test fixtures"""
1616
self.medulla_id = 'FBbt_00003748'
1717
# Expected count based on VFB data (as of test creation)
18-
# Allowing tolerance for data updates
19-
self.expected_count = 471
20-
self.count_tolerance = 5 # Allow ±5 for data updates
18+
# Data can grow over time, so we test for minimum expected count
19+
self.expected_count = 470 # Minimum expected count (actual was 472)
20+
self.count_tolerance = 5 # Allow some tolerance for variations
2121

2222
def test_neurons_part_here_returns_results(self):
2323
"""Test that NeuronsPartHere query returns results for medulla"""
@@ -49,23 +49,22 @@ def test_neurons_part_here_result_count(self):
4949
)
5050

5151
actual_count = len(results_df)
52-
count_diff = abs(actual_count - self.expected_count)
52+
count_diff = actual_count - self.expected_count
5353

54-
print(f"Expected: {self.expected_count} results")
54+
print(f"Expected: at least {self.expected_count} results")
5555
print(f"Actual: {actual_count} results")
56-
print(f"Difference: {count_diff}")
5756

58-
# Allow some tolerance for data updates
59-
self.assertLessEqual(
60-
count_diff,
61-
self.count_tolerance,
62-
f"Result count {actual_count} differs from expected {self.expected_count} by more than {self.count_tolerance}"
57+
# Data can grow over time, so we require at least the expected minimum
58+
self.assertGreaterEqual(
59+
actual_count,
60+
self.expected_count,
61+
f"Result count {actual_count} is less than expected minimum {self.expected_count}"
6362
)
6463

6564
if count_diff > 0:
66-
print(f" Count differs by {count_diff} (within tolerance of {self.count_tolerance})")
65+
print(f" Count increased by {count_diff} (data growth)")
6766
else:
68-
print(f"✓ Exact count match: {actual_count}")
67+
print(f"✓ Minimum count met: {actual_count}")
6968

7069
def test_neurons_part_here_result_structure(self):
7170
"""Test that results have the expected structure with required columns"""

src/vfbquery/solr_result_cache.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,17 @@ def wrapper(*args, **kwargs):
653653
preview = kwargs.get('preview', True) # Default is True
654654
cache_term_id = f"{term_id}_preview_{preview}"
655655

656-
# Include similarity_score parameter in cache key for similarity queries
657-
# This ensures different similarity scores are cached separately
658-
similarity_query_types = ['similar_neurons', 'similar_morphology', 'similar_morphology_part_of',
659-
'similar_morphology_part_of_exp', 'similar_morphology_nb',
660-
'similar_morphology_nb_exp', 'similar_morphology_userdata']
661-
if query_type in similarity_query_types:
662-
similarity_score = kwargs.get('similarity_score', 'NBLAST_score') # Default
663-
cache_term_id = f"{cache_term_id}_score_{similarity_score}"
656+
# Include return_dataframe parameter in cache key for queries that support it
657+
# This ensures DataFrame and dict results are cached separately
658+
dataframe_query_types = ['neurons_part_here', 'neurons_synaptic', 'neurons_presynaptic',
659+
'neurons_postsynaptic', 'similar_neurons', 'similar_morphology',
660+
'similar_morphology_part_of', 'similar_morphology_part_of_exp',
661+
'similar_morphology_nb', 'similar_morphology_nb_exp',
662+
'similar_morphology_userdata', 'neurons_part_here', 'neurons_synaptic',
663+
'neurons_presynaptic', 'neurons_postsynaptic']
664+
if query_type in dataframe_query_types:
665+
return_dataframe = kwargs.get('return_dataframe', True) # Default is True
666+
cache_term_id = f"{cache_term_id}_dataframe_{return_dataframe}"
664667

665668
cache = get_solr_cache()
666669

0 commit comments

Comments
 (0)