From 88b8459b08f974cf4cea48176384a9af33c7a3d2 Mon Sep 17 00:00:00 2001 From: Guillaume Viejo Date: Wed, 15 Jan 2025 15:35:38 -0500 Subject: [PATCH 1/5] Fixing link in index.rst --- doc/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/index.rst b/doc/index.rst index 1fc39aab..c61a65b5 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -64,7 +64,7 @@ pynapple: python neural analysis package .. grid-item-card:: Time Series :text-align: center - :link: ./user_guide/03_core_methods.html + :link: ./user_guide/01_core_methods.html .. image:: _static/example_thumbs/timeseries.svg :class: dark-light @@ -106,7 +106,7 @@ pynapple: python neural analysis package .. grid-item-card:: Filtering :text-align: center - :link: ./user_guide/07_decoding.html + :link: ./user_guide/12_filtering.html .. image:: _static/example_thumbs/filtering.svg :class: dark-light From d3d89281e57b37ebcf5a18ac911592f136563e88 Mon Sep 17 00:00:00 2001 From: Guillaume Viejo Date: Wed, 15 Jan 2025 15:38:08 -0500 Subject: [PATCH 2/5] Removed deploy to gh-page --- .github/workflows/documentation.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 851150d5..781e23a3 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -18,11 +18,11 @@ jobs: - name: Sphinx build run: | sphinx-build doc _build - - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - with: - publish_branch: gh-pages - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: _build/ - force_orphan: true \ No newline at end of file +# - name: Deploy to GitHub Pages +# uses: peaceiris/actions-gh-pages@v3 +# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} +# with: +# publish_branch: gh-pages +# github_token: ${{ secrets.GITHUB_TOKEN }} +# publish_dir: _build/ +# force_orphan: true \ No newline at end of file From 371b312b66196cbd044a41dc7f8647fba736aa6a Mon Sep 17 00:00:00 2001 From: Guillaume Viejo Date: Wed, 15 Jan 2025 16:05:04 -0500 Subject: [PATCH 3/5] Fixing link --- doc/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/index.rst b/doc/index.rst index c61a65b5..1c406bea 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -64,7 +64,7 @@ pynapple: python neural analysis package .. grid-item-card:: Time Series :text-align: center - :link: ./user_guide/01_core_methods.html + :link: ./user_guide/03_core_methods.html .. image:: _static/example_thumbs/timeseries.svg :class: dark-light From 9acd00d7b78481fa754fda24bd0eccf72ba08bfa Mon Sep 17 00:00:00 2001 From: Guillaume Viejo Date: Wed, 15 Jan 2025 17:24:09 -0500 Subject: [PATCH 4/5] Reverst tsdframe getitem --- pynapple/core/time_series.py | 4 +- tests/test_time_series.py | 79 ++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/pynapple/core/time_series.py b/pynapple/core/time_series.py index dc1e84ff..734a0c4b 100644 --- a/pynapple/core/time_series.py +++ b/pynapple/core/time_series.py @@ -1206,8 +1206,8 @@ def __getitem__(self, key, *args, **kwargs): else: index = self.index.__getitem__(key) - if isinstance(index, Number): - index = np.array([index]) + # if isinstance(index, Number): + # index = np.array([index]) if all(is_array_like(a) for a in [index, output]): if isinstance(key, tuple): diff --git a/tests/test_time_series.py b/tests/test_time_series.py index 354104ed..48b45921 100755 --- a/tests/test_time_series.py +++ b/tests/test_time_series.py @@ -1029,28 +1029,34 @@ def test_horizontal_slicing(self, tsdframe, index, nap_type): ], ) def test_vertical_slicing(self, tsdframe, index): - assert isinstance(tsdframe[index], nap.TsdFrame) - if len(tsdframe[index] == 1): - # use ravel to ignore shape mismatch - np.testing.assert_array_almost_equal( - tsdframe.values[index].ravel(), tsdframe[index].values.ravel() - ) + if isinstance(index, int): + assert isinstance(tsdframe[index], np.ndarray) else: + assert isinstance(tsdframe[index], nap.TsdFrame) + + output = tsdframe[index] + if isinstance(output, nap.TsdFrame): + if len(output == 1): + # use ravel to ignore shape mismatch + np.testing.assert_array_almost_equal( + tsdframe.values[index].ravel(), output.values.ravel() + ) + else: + np.testing.assert_array_almost_equal( + tsdframe.values[index], output.values + ) + assert isinstance(output.time_support, nap.IntervalSet) np.testing.assert_array_almost_equal( - tsdframe.values[index], tsdframe[index].values + output.time_support, tsdframe.time_support ) - assert isinstance(tsdframe[index].time_support, nap.IntervalSet) - np.testing.assert_array_almost_equal( - tsdframe[index].time_support, tsdframe.time_support - ) - if len(tsdframe.metadata_columns): - assert np.all(tsdframe[index].metadata_columns == tsdframe.metadata_columns) - assert np.all(tsdframe[index].metadata_index == tsdframe.metadata_index) + if len(tsdframe.metadata_columns): + assert np.all(output.metadata_columns == tsdframe.metadata_columns) + assert np.all(output.metadata_index == tsdframe.metadata_index) @pytest.mark.parametrize( "row", [ - 0, + # 0, [0, 2], slice(20, 30), np.hstack([np.zeros(10, bool), True, True, True, np.zeros(87, bool)]), @@ -1108,28 +1114,33 @@ def test_vert_and_horz_slicing(self, tsdframe, row, col, expected): else: assert isinstance(tsdframe[row, col], expected) - if len(tsdframe[row, col] == 1): - # use ravel to ignore shape mismatch + output = tsdframe[row, col] + + if isinstance(output, nap.TsdFrame): + if len(tsdframe[row, col] == 1): + # use ravel to ignore shape mismatch + np.testing.assert_array_almost_equal( + tsdframe.values[row, col].ravel(), tsdframe[row, col].values.ravel() + ) + else: + np.testing.assert_array_almost_equal( + tsdframe.values[row, col], tsdframe[row, col].values + ) + assert isinstance(tsdframe[row, col].time_support, nap.IntervalSet) np.testing.assert_array_almost_equal( - tsdframe.values[row, col].ravel(), tsdframe[row, col].values.ravel() + tsdframe[row, col].time_support, tsdframe.time_support ) + if isinstance(tsdframe[row, col], nap.TsdFrame) and len( + tsdframe[row, col].metadata_columns + ): + assert np.all( + tsdframe[row, col].metadata_columns == tsdframe.metadata_columns + ) + assert np.all( + tsdframe[row, col].metadata_index == tsdframe.metadata_index[col] + ) else: - np.testing.assert_array_almost_equal( - tsdframe.values[row, col], tsdframe[row, col].values - ) - assert isinstance(tsdframe[row, col].time_support, nap.IntervalSet) - np.testing.assert_array_almost_equal( - tsdframe[row, col].time_support, tsdframe.time_support - ) - if isinstance(tsdframe[row, col], nap.TsdFrame) and len( - tsdframe[row, col].metadata_columns - ): - assert np.all( - tsdframe[row, col].metadata_columns == tsdframe.metadata_columns - ) - assert np.all( - tsdframe[row, col].metadata_index == tsdframe.metadata_index[col] - ) + np.testing.assert_array_almost_equal(output, tsdframe.values[row,col]) @pytest.mark.parametrize("index", [0, [0, 2]]) def test_str_indexing(self, tsdframe, index): From e8c8ea07c22465f8bbea1bc043fd821e4fa2f0ee Mon Sep 17 00:00:00 2001 From: Guillaume Viejo Date: Wed, 15 Jan 2025 17:25:40 -0500 Subject: [PATCH 5/5] linting --- tests/test_time_series.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_time_series.py b/tests/test_time_series.py index 48b45921..7a17aedf 100755 --- a/tests/test_time_series.py +++ b/tests/test_time_series.py @@ -1120,7 +1120,8 @@ def test_vert_and_horz_slicing(self, tsdframe, row, col, expected): if len(tsdframe[row, col] == 1): # use ravel to ignore shape mismatch np.testing.assert_array_almost_equal( - tsdframe.values[row, col].ravel(), tsdframe[row, col].values.ravel() + tsdframe.values[row, col].ravel(), + tsdframe[row, col].values.ravel(), ) else: np.testing.assert_array_almost_equal( @@ -1137,10 +1138,11 @@ def test_vert_and_horz_slicing(self, tsdframe, row, col, expected): tsdframe[row, col].metadata_columns == tsdframe.metadata_columns ) assert np.all( - tsdframe[row, col].metadata_index == tsdframe.metadata_index[col] + tsdframe[row, col].metadata_index + == tsdframe.metadata_index[col] ) else: - np.testing.assert_array_almost_equal(output, tsdframe.values[row,col]) + np.testing.assert_array_almost_equal(output, tsdframe.values[row, col]) @pytest.mark.parametrize("index", [0, [0, 2]]) def test_str_indexing(self, tsdframe, index):