Skip to content

Commit

Permalink
fix nan and empty units
Browse files Browse the repository at this point in the history
  • Loading branch information
zm711 committed Nov 22, 2024
1 parent bf96fe1 commit 5b77ba1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ def _compute_metrics(self, sorting_analyzer, unit_ids=None, verbose=False, metri
# add NaN for empty units
if len(empty_unit_ids) > 0:
metrics.loc[empty_unit_ids] = np.nan
# num_spikes is an int and should be 0
if "num_spikes" in metrics.columns:
metrics.loc[empty_unit_ids, ["num_spikes"]] = 0

# we use the convert_dtypes to convert the columns to the most appropriate dtype and avoid object columns
# (in case of NaN values)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,15 @@ def test_empty_units(sorting_analyzer_simple):
seed=2205,
)

# num_spikes are ints not nans so we confirm empty units are nans for everything except
# num_spikes which should be 0
nan_containing_columns = [column for column in metrics_empty.columns if column != "num_spikes"]
for empty_unit_id in sorting_empty.get_empty_unit_ids():
from pandas import isnull

assert np.all(isnull(metrics_empty.loc[empty_unit_id].values))
assert np.all(isnull(metrics_empty.loc[empty_unit_id, nan_containing_columns].values))
if "num_spikes" in metrics_empty.columns:
assert metrics_empty.loc[empty_unit_id, ["num_spikes"]] == 0


# TODO @alessio all theses old test should be moved in test_metric_functions.py or test_pca_metrics()
Expand Down

0 comments on commit 5b77ba1

Please sign in to comment.