@@ -465,14 +465,14 @@ def get_speed_tuning(self, binsize):
465465 nc , start_max * binsize :(start_max + 1 ) * binsize ]
466466 other_values = np .delete (celltraces_sorted_sp [nc , :], range (
467467 start_max * binsize , (start_max + 1 ) * binsize ))
468- (_ , peak_run .ptest_sp [nc ]) = st . ks_2samp (
468+ (_ , peak_run .ptest_sp [nc ]) = nonraising_ks_2samp (
469469 test_values , other_values )
470470 else :
471471 test_values = celltraces_sorted_sp [
472472 nc , start_min * binsize :(start_min + 1 ) * binsize ]
473473 other_values = np .delete (celltraces_sorted_sp [nc , :], range (
474474 start_min * binsize , (start_min + 1 ) * binsize ))
475- (_ , peak_run .ptest_sp [nc ]) = st . ks_2samp (
475+ (_ , peak_run .ptest_sp [nc ]) = nonraising_ks_2samp (
476476 test_values , other_values )
477477 temp = binned_cells_vis [nc , :, 0 ]
478478 start_max = temp .argmax ()
@@ -489,7 +489,7 @@ def get_speed_tuning(self, binsize):
489489 nc , start_min * binsize :(start_min + 1 ) * binsize ]
490490 other_values = np .delete (celltraces_sorted_vis [nc , :], range (
491491 start_min * binsize , (start_min + 1 ) * binsize ))
492- (_ , peak_run .ptest_vis [nc ]) = st . ks_2samp (
492+ (_ , peak_run .ptest_vis [nc ]) = nonraising_ks_2samp (
493493 test_values , other_values )
494494
495495 return binned_dx_sp , binned_cells_sp , binned_dx_vis , binned_cells_vis , peak_run
@@ -581,3 +581,13 @@ def row_from_cell_id(self, csid=None, idx=None):
581581 else :
582582 raise Exception ("Could not find row for csid(%s) idx(%s)" % (str (csid ), str (idx )))
583583
584+
585+ def nonraising_ks_2samp (data1 , data2 , ** kwargs ):
586+ """ scipy.stats.ks_2samp now raises a ValueError if one of the input arrays
587+ is of length 0. Previously it signaled this case by returning nans. This
588+ function restores the prior behavior.
589+ """
590+
591+ if min (len (data1 ), len (data2 )) == 0 :
592+ return (np .nan , np .nan )
593+ return st .ks_2samp (data1 , data2 , ** kwargs )
0 commit comments