@@ -212,21 +212,26 @@ class TestReturnNullDataLightweight:
212212 """When return_null_data=True (without return_full_results),
213213 result_dict should contain null metadata but NOT expression matrices."""
214214
215- def test_null_key_present (self ):
215+ def test_null_key_present_without_return_full_results (self ):
216+ """return_null_data=True alone should return the result dict."""
216217 adata = _make_adata ()
217218 result = kompot .de (
218219 adata , "condition" , "A" , "B" ,
219220 gp = kompot .GPSettings (** _FAST_GP ),
220221 fdr = FDRSettings (null_genes = 10 , null_seed = 42 ),
221222 output = OutputSettings (
222- return_full_results = True ,
223+ return_full_results = False ,
223224 return_null_data = True ,
224225 progress = False ,
225226 ),
226227 )
228+ assert isinstance (result , dict )
227229 assert "null" in result
230+ assert "table" in result # result dict always has a table
228231
229- def test_lightweight_has_table_and_metadata (self ):
232+ def test_lightweight_no_expression_in_null (self ):
233+ """return_null_data=True without return_full_results should return
234+ the dict but the null entry should NOT have expression matrices."""
230235 adata = _make_adata ()
231236 result = kompot .de (
232237 adata , "condition" , "A" , "B" ,
@@ -236,23 +241,38 @@ def test_lightweight_has_table_and_metadata(self):
236241 return_full_results = False ,
237242 return_null_data = True ,
238243 progress = False ,
239- inplace = False ,
240244 ),
241245 )
242- # return_null_data alone requires return_full_results to get the dict
243- # With return_full_results=False and inplace=False, result is None.
244- # The null data only surfaces through the result_dict, which requires
245- # return_full_results=True. Let's test with it on.
246-
247- def test_no_expression_matrices_when_lightweight (self ):
248- """return_null_data=True without return_full_results should NOT
249- include the large expression matrices in the null dict."""
246+ null = result ["null" ]
247+ assert isinstance (null ["table" ], pd .DataFrame )
248+ assert null ["seed" ] == 42
249+ for key in (
250+ "condition1_imputed" , "condition2_imputed" ,
251+ "fold_change" , "fold_change_zscores" ,
252+ ):
253+ assert key not in null , f"Lightweight mode should not include { key } "
254+
255+ def test_return_null_data_with_copy (self ):
256+ """return_null_data=True with copy=True returns (dict, adata)."""
250257 adata = _make_adata ()
251- # return_null_data=True but return_full_results=False:
252- # We need return_full_results=True to actually get the dict back,
253- # so the distinction is: return_null_data alone triggers lightweight,
254- # return_full_results triggers full. Test the internal _compute_fdr
255- # directly.
258+ result = kompot .de (
259+ adata , "condition" , "A" , "B" ,
260+ gp = kompot .GPSettings (** _FAST_GP ),
261+ fdr = FDRSettings (null_genes = 10 , null_seed = 42 ),
262+ output = OutputSettings (
263+ return_full_results = False ,
264+ return_null_data = True ,
265+ copy = True ,
266+ progress = False ,
267+ ),
268+ )
269+ assert isinstance (result , tuple )
270+ result_dict , adata_copy = result
271+ assert "null" in result_dict
272+
273+ def test_no_expression_matrices_when_lightweight_internal (self ):
274+ """Test _compute_fdr directly: return_null_data without
275+ return_full_results should not capture expression matrices."""
256276 from kompot .anndata ._de_helpers import _compute_fdr
257277
258278 n_real = 10
0 commit comments