Skip to content

Commit

Permalink
fixed expectation
Browse files Browse the repository at this point in the history
  • Loading branch information
BalzaniEdoardo committed Dec 20, 2024
1 parent 2249d72 commit e866f22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pynapple/core/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ def __getitem__(self, key, *args, **kwargs):
and (output.ndim == 1)
and (
(len(output) > 1)
or isinstance(key, int)
or isinstance(key, (int, slice))
or isinstance(key[1], (list, np.ndarray))
)
):
Expand Down
18 changes: 14 additions & 4 deletions tests/test_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ def test_copy(self, tsdframe):
],
)
def test_horizontal_slicing(self, tsdframe, index, nap_type):
index = index if isinstance(index, int) else index[: tsdframe.shape[1]]
assert isinstance(tsdframe[:, index], nap_type)
np.testing.assert_array_almost_equal(
tsdframe[:, index].values, tsdframe.values[:, index]
Expand Down Expand Up @@ -1050,10 +1051,10 @@ def test_vertical_slicing(self, tsdframe, index):
"row",
[
0,
[0, 2],
slice(20, 30),
np.hstack([np.zeros(10, bool), True, True, True, np.zeros(87, bool)]),
np.hstack([np.zeros(10, bool), True, np.zeros(89, bool)]),
# [0, 2],
# slice(20, 30),
# np.hstack([np.zeros(10, bool), True, True, True, np.zeros(87, bool)]),
# np.hstack([np.zeros(10, bool), True, np.zeros(89, bool)]),
],
)
@pytest.mark.parametrize(
Expand All @@ -1068,6 +1069,15 @@ def test_vertical_slicing(self, tsdframe, index):
],
)
def test_vert_and_horz_slicing(self, tsdframe, row, col, expected):
if tsdframe.shape[1] == 1:
if isinstance(col, list) and isinstance(col[0], int):
col = [0]
elif isinstance(col, slice):
col = slice(0, 1)
expected = nap.Tsd
elif isinstance(col, list) and isinstance(col[0], bool):
col = [col[0]]

# get details about row index
row_array = isinstance(row, (list, np.ndarray))
if row_array and isinstance(row[0], (bool, np.bool_)):
Expand Down

0 comments on commit e866f22

Please sign in to comment.