@@ -378,13 +378,8 @@ def phenotype_data(
378378 return pd .DataFrame ()
379379
380380 # 3. Get sample metadata for all samples that have phenotype data
381- # The sample_metadata method does not accept a 'df' argument.
382- # We need to fetch the metadata first, then merge and filter.
383381 try :
384- df_metadata = self .sample_metadata (
385- sample_sets = sample_sets_norm ,
386- sample_query_options = sample_query_options ,
387- )
382+ df_metadata = self .sample_metadata (sample_sets = sample_sets_norm )
388383 except Exception as e :
389384 warnings .warn (f"Error fetching sample metadata: { e } " )
390385 return pd .DataFrame ()
@@ -394,7 +389,7 @@ def phenotype_data(
394389 return pd .DataFrame ()
395390
396391 # 4. Merge phenotype data with metadata
397- # Filter phenotype data to samples present in metadata before merging
392+ # Filter phenotype data to samples present in metadata before merging
398393 metadata_sample_ids = set (df_metadata ["sample_id" ].unique ())
399394 df_phenotypes_filtered = df_phenotypes [
400395 df_phenotypes ["sample_id" ].isin (metadata_sample_ids )
@@ -407,8 +402,9 @@ def phenotype_data(
407402 # 5. Apply user's sample_query if provided
408403 if sample_query :
409404 try :
410- # Use pandas query method to filter the merged data
411- df_merged = df_merged .query (sample_query )
405+ df_merged = df_merged .query (
406+ sample_query , ** (sample_query_options or {})
407+ )
412408 except Exception as e :
413409 warnings .warn (f"Error applying sample_query '{ sample_query } ': { e } " )
414410 return pd .DataFrame ()
0 commit comments