From 65d7583dc746f8212b928946ff336d0ba8d6e358 Mon Sep 17 00:00:00 2001 From: Michael Harms Date: Sun, 31 May 2026 20:01:19 -0700 Subject: [PATCH 1/2] fixed failing unit tests on github wf --- src/tfscreen/genetics/combine_mutation_effects.py | 3 ++- src/tfscreen/simulate/selection_experiment.py | 8 +++++--- .../components/transformation/test__congression.py | 2 +- tests/tfscreen/util/io/test_read_dataframe.py | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/tfscreen/genetics/combine_mutation_effects.py b/src/tfscreen/genetics/combine_mutation_effects.py index 07916df2..64dee1fd 100644 --- a/src/tfscreen/genetics/combine_mutation_effects.py +++ b/src/tfscreen/genetics/combine_mutation_effects.py @@ -68,7 +68,8 @@ def combine_mutation_effects( g_lookup.loc["wt", :] = np.nan # Convert from wide (genotypes) to long (single mutations) format - stacked_muts = g_lookup.stack() + # dropna() required because pandas 3.x stack() no longer drops NaN by default + stacked_muts = g_lookup.stack().dropna() if stacked_muts.empty: # Case where only 'wt' or no multi-mutants exist return single_mutant_effects.iloc[0:0].reindex(g_lookup.index, fill_value=0) diff --git a/src/tfscreen/simulate/selection_experiment.py b/src/tfscreen/simulate/selection_experiment.py index e1f03c83..77e7f0d4 100644 --- a/src/tfscreen/simulate/selection_experiment.py +++ b/src/tfscreen/simulate/selection_experiment.py @@ -720,7 +720,8 @@ def _sim_growth( all_kt = genotype_vs_kt[transformants] # Expand the 2D mask to 3D to match the shape of all_kt. - expanded_mask = np.broadcast_to(trans_mask[:, :, np.newaxis], all_kt.shape) + # .copy() required: numpy 2.x rejects read-only broadcast arrays as ma masks + expanded_mask = np.broadcast_to(trans_mask[:, :, np.newaxis], all_kt.shape).copy() masked_kt = ma.array(all_kt, mask=expanded_mask) # Calculate the kt for each cell by combining effects of plasmids @@ -1054,8 +1055,9 @@ def _simulate_library_group( # stack, these will be removed. genotype_vs_kt_pivot = sparse_pivot.reindex(ordered_genotypes, fill_value=0) - # Create a 2D array of (genotype,conditions) holding kt. - genotype_vs_kt = genotype_vs_kt_pivot.to_numpy() + # Create a 2D array of (genotype,conditions) holding kt. + # .copy() required: pandas 3.x CoW returns a read-only view from to_numpy() + genotype_vs_kt = genotype_vs_kt_pivot.to_numpy().copy() # Add per-tube environmental noise: one delta_k per condition, shared across # all genotypes in that tube. tube_noise_sigma is in growth-rate units diff --git a/tests/tfscreen/tfmodel/components/transformation/test__congression.py b/tests/tfscreen/tfmodel/components/transformation/test__congression.py index acd667b8..e856627d 100644 --- a/tests/tfscreen/tfmodel/components/transformation/test__congression.py +++ b/tests/tfscreen/tfmodel/components/transformation/test__congression.py @@ -38,7 +38,7 @@ def test_empirical_cdf(): assert cdf.shape == (5,) assert cdf[0] == 0.16666667 # Interp 0.0 at 0.1 returns y[0] assert jnp.isclose(cdf[2], 0.5) # 0.5 is exactly in theta - assert cdf[4] == 0.8333333 # Interp 1.0 at 0.9 returns y[2] + assert jnp.isclose(cdf[4], 5/6, atol=1e-5) # Interp 1.0 at 0.9 returns y[2] # ------------------------------------------------------------------------- diff --git a/tests/tfscreen/util/io/test_read_dataframe.py b/tests/tfscreen/util/io/test_read_dataframe.py index c39ceb24..e656c365 100644 --- a/tests/tfscreen/util/io/test_read_dataframe.py +++ b/tests/tfscreen/util/io/test_read_dataframe.py @@ -211,5 +211,5 @@ def test_genotype_as_index_not_categorized(): df = pd.DataFrame({"genotype": ["wt", "A1T"], "value": [1, 2]}) result = read_dataframe(df, index_column="genotype") assert result.index.name == "genotype" - # Index should be plain strings, not categorical - assert result.index.dtype == object \ No newline at end of file + # Index should be plain strings, not categorical (dtype varies: object or StringDtype) + assert not isinstance(result.index.dtype, pd.CategoricalDtype) \ No newline at end of file From eb2cebd0ccd7bea2a1cd1848d90741f0154bd9ed Mon Sep 17 00:00:00 2001 From: Michael Harms Date: Sun, 31 May 2026 20:11:12 -0700 Subject: [PATCH 2/2] version bump to 0.4.0 --- src/tfscreen/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tfscreen/__version__.py b/src/tfscreen/__version__.py index f87a6b37..663dd15d 100644 --- a/src/tfscreen/__version__.py +++ b/src/tfscreen/__version__.py @@ -5,5 +5,5 @@ Version string. """ -VERSION = (0, 3, 1) +VERSION = (0, 4, 0) __version__ = '.'.join(map(str, VERSION))