Skip to content

Commit

Permalink
Fixing linting
Browse files Browse the repository at this point in the history
  • Loading branch information
gviejo committed Jan 7, 2025
1 parent 0abd0d8 commit 68b638a
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tests/test_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

"""Tests of decoding for `pynapple` package."""

import pynapple as nap
import numpy as np
import pandas as pd
import pytest

import pynapple as nap


def get_testing_set_1d():
feature = nap.Tsd(t=np.arange(0, 100, 1), d=np.repeat(np.arange(0, 2), 50))
Expand All @@ -36,9 +37,10 @@ def test_decode_1d():
tmp[0:50, 1] = 0.0
np.testing.assert_array_almost_equal(proba.values, tmp)


def test_decode_1d_with_TsdFrame():
feature, group, tc, ep = get_testing_set_1d()
count = group.count(bin_size=1, ep = ep)
count = group.count(bin_size=1, ep=ep)
decoded, proba = nap.decode_1d(tc, count, ep, bin_size=1)
assert isinstance(decoded, nap.Tsd)
assert isinstance(proba, nap.TsdFrame)
Expand All @@ -50,6 +52,7 @@ def test_decode_1d_with_TsdFrame():
tmp[0:50, 1] = 0.0
np.testing.assert_array_almost_equal(proba.values, tmp)


def test_decode_1d_with_feature():
feature, group, tc, ep = get_testing_set_1d()
decoded, proba = nap.decode_1d(tc, group, ep, bin_size=1, feature=feature)
Expand All @@ -63,7 +66,8 @@ def test_decode_1d_with_feature():
tmp[50:, 0] = 0.0
tmp[0:50, 1] = 0.0
np.testing.assert_array_almost_equal(proba.values, tmp)



def test_decode_1d_with_dict():
feature, group, tc, ep = get_testing_set_1d()
group = dict(group)
Expand All @@ -79,18 +83,21 @@ def test_decode_1d_with_dict():
tmp[0:50, 1] = 0.0
np.testing.assert_array_almost_equal(proba.values, tmp)


def test_decode_1d_with_wrong_feature():
feature, group, tc, ep = get_testing_set_1d()
with pytest.raises(RuntimeError) as e_info:
nap.decode_1d(tc, group, ep, bin_size=1, feature=[1,2,3])
nap.decode_1d(tc, group, ep, bin_size=1, feature=[1, 2, 3])
assert str(e_info.value) == "Unknown format for feature in decode_1d"


def test_decode_1d_with_time_units():
feature, group, tc, ep = get_testing_set_1d()
for t, tu in zip([1, 1e3, 1e6], ["s", "ms", "us"]):
decoded, proba = nap.decode_1d(tc, group, ep, 1.0 * t, time_units=tu)
np.testing.assert_array_almost_equal(feature.values, decoded.values)


def test_decoded_1d_raise_errors():
feature, group, tc, ep = get_testing_set_1d()
with pytest.raises(Exception) as e_info:
Expand Down Expand Up @@ -150,9 +157,10 @@ def test_decode_2d():
tmp[51:100:2, 1] = 1
np.testing.assert_array_almost_equal(proba[:, :, 1], tmp)


def test_decode_2d_with_TsdFrame():
features, group, tc, ep, xy = get_testing_set_2d()
count = group.count(bin_size=1, ep = ep)
count = group.count(bin_size=1, ep=ep)
decoded, proba = nap.decode_2d(tc, count, ep, 1, xy)

assert isinstance(decoded, nap.TsdFrame)
Expand All @@ -169,7 +177,8 @@ def test_decode_2d_with_TsdFrame():
tmp[1:50:2, 0] = 1
tmp[51:100:2, 1] = 1
np.testing.assert_array_almost_equal(proba[:, :, 1], tmp)



def test_decode_2d_with_dict():
features, group, tc, ep, xy = get_testing_set_2d()
group = dict(group)
Expand All @@ -190,6 +199,7 @@ def test_decode_2d_with_dict():
tmp[51:100:2, 1] = 1
np.testing.assert_array_almost_equal(proba[:, :, 1], tmp)


def test_decode_2d_with_feature():
features, group, tc, ep, xy = get_testing_set_2d()
decoded, proba = nap.decode_2d(tc, group, ep, 1, xy)
Expand Down

0 comments on commit 68b638a

Please sign in to comment.