Skip to content

Commit d591eeb

Browse files
authored
Remove nan/inf values for pearsonr (#1209)
1 parent 9f93308 commit d591eeb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

models/ecoli/analysis/variant/growth_correlations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def plot_bar(self, ax, cell_property, growth_rates, xlabel, tick_labels, growth_
3737
all_r = np.zeros((n_subproperties, n_growth_rates))
3838
for i, property in enumerate(cell_property):
3939
for j, growth in enumerate(growth_rates):
40-
all_r[i, j] = stats.pearsonr(property[:len(growth)], growth)[0]
40+
filter_mask = np.isfinite(property[:len(growth)]) & np.isfinite(growth) # filter to prevent pearsonr ValueError
41+
if np.any(filter_mask):
42+
all_r[i, j] = stats.pearsonr(property[:len(growth)][filter_mask], growth[filter_mask])[0]
4143

4244
width = 0.8 / n_growth_rates
4345
offsets = np.arange(n_growth_rates) * width - 0.4 + width / 2

0 commit comments

Comments
 (0)