Skip to content

Commit

Permalink
Merge pull request #397 from pynapple-org/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
gviejo authored Jan 17, 2025
2 parents ae9129b + 925cb43 commit 440a9f4
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pynapple is a light-weight python library for neurophysiological data analysis.
New release :fire:
------------------

### pynapple >= 0.8
### pynapple >= 0.8.1

The objects `IntervalSet`, `TsdFrame` and `TsGroup` inherits a new metadata class. It is now possible to add labels for
each interval of an `IntervalSet`, each column of a `TsdFrame` and each unit of a `TsGroup`.
Expand Down
4 changes: 4 additions & 0 deletions doc/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ of the Flatiron institute.

## Releases

### 0.8.1 (2025-01-17)

- Bugfix : time support was not updated for `bin_average` and `interpolate` with new `_initialize_tsd_output` method

### 0.8.0 (2025-01-15)

- New private class: `_MetadataMixin` (core/metadata_class.py). Can be inherited by `IntervalSet`, `TsdFrame` and `TsGroup`.
Expand Down
2 changes: 1 addition & 1 deletion pynapple/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.8.0"
__version__ = "0.8.1"
from .core import (
IntervalSet,
Ts,
Expand Down
8 changes: 5 additions & 3 deletions pynapple/core/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def bin_average(self, bin_size, ep=None, time_units="s"):

t, d = _bin_average(time_array, data_array, starts, ends, bin_size)

return _initialize_tsd_output(self, d, time_index=t)
return _initialize_tsd_output(self, d, time_index=t, time_support=ep)

def dropna(self, update_time_support=True):
"""Drop every row containing NaNs. By default, the time support is updated to start and end around the time points that are non NaNs.
Expand Down Expand Up @@ -477,7 +477,9 @@ def convolve(self, array, ep=None, trim="both"):

new_data_array = _convolve(time_array, data_array, starts, ends, array, trim)

return _initialize_tsd_output(self, new_data_array, time_index=time_array)
return _initialize_tsd_output(
self, new_data_array, time_index=time_array, time_support=ep
)

def smooth(self, std, windowsize=None, time_units="s", size_factor=100, norm=True):
"""Smooth a time series with a gaussian kernel.
Expand Down Expand Up @@ -634,7 +636,7 @@ def interpolate(self, ts, ep=None, left=None, right=None):

start += len(t)

return _initialize_tsd_output(self, new_d, time_index=new_t)
return _initialize_tsd_output(self, new_d, time_index=new_t, time_support=ep)


class TsdTensor(_BaseTsd):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pynapple"
version = "0.8.0"
version = "0.8.1"
description = "PYthon Neural Analysis Package Pour Laboratoires d’Excellence"
readme = "README.md"
authors = [{ name = "Guillaume Viejo", email = "[email protected]" }]
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/pynapple-org/pynapple',
version='v0.8.0',
version='v0.8.1',
zip_safe=False,
long_description_content_type='text/markdown',
download_url='https://github.com/pynapple-org/pynapple/archive/refs/tags/v0.8.0.tar.gz'
download_url='https://github.com/pynapple-org/pynapple/archive/refs/tags/v0.8.1.tar.gz'
)
86 changes: 86 additions & 0 deletions tests/test_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,35 @@ def test_smooth_raise_error(self, tsd):
],
)
class TestTsd:

@pytest.mark.parametrize("delta_ep", [(1, -1), (-1, -1), (1, 1)])
def test_bin_average_time_support(self, tsd, delta_ep):
ep = nap.IntervalSet(
tsd.time_support.start[0] + delta_ep[0],
tsd.time_support.end[0] + delta_ep[1],
)
out = tsd.bin_average(0.1, ep=ep)
assert np.all(out.time_support == ep)

@pytest.mark.parametrize("delta_ep", [(1, -1), (-1, -1), (1, 1)])
def test_convolve_time_support(self, tsd, delta_ep):
ep = nap.IntervalSet(
tsd.time_support.start[0] + delta_ep[0],
tsd.time_support.end[0] + delta_ep[1],
)
out = tsd.convolve(np.ones(10), ep=ep)
assert np.all(out.time_support == ep)

@pytest.mark.parametrize("delta_ep", [(1, -1), (-1, -1), (1, 1)])
def test_interpolate_time_support(self, tsd, delta_ep):
ep = nap.IntervalSet(
tsd.time_support.start[0] + delta_ep[0],
tsd.time_support.end[0] + delta_ep[1],
)
ts = nap.Ts(np.linspace(0, 10, 20))
out = tsd.interpolate(ts, ep=ep)
assert np.all(out.time_support == ep)

def test_as_series(self, tsd):
assert isinstance(tsd.as_series(), pd.Series)

Expand Down Expand Up @@ -978,6 +1007,35 @@ def test_interpolate_with_ep(self, tsd):
],
)
class TestTsdFrame:

@pytest.mark.parametrize("delta_ep", [(1, -1), (-1, -1), (1, 1)])
def test_bin_average_time_support(self, tsdframe, delta_ep):
ep = nap.IntervalSet(
tsdframe.time_support.start[0] + delta_ep[0],
tsdframe.time_support.end[0] + delta_ep[1],
)
out = tsdframe.bin_average(0.1, ep=ep)
assert np.all(out.time_support == ep)

@pytest.mark.parametrize("delta_ep", [(1, -1), (-1, -1), (1, 1)])
def test_convolve_time_support(self, tsdframe, delta_ep):
ep = nap.IntervalSet(
tsdframe.time_support.start[0] + delta_ep[0],
tsdframe.time_support.end[0] + delta_ep[1],
)
out = tsdframe.convolve(np.ones(10), ep=ep)
assert np.all(out.time_support == ep)

@pytest.mark.parametrize("delta_ep", [(1, -1), (-1, -1), (1, 1)])
def test_interpolate_time_support(self, tsdframe, delta_ep):
ep = nap.IntervalSet(
tsdframe.time_support.start[0] + delta_ep[0],
tsdframe.time_support.end[0] + delta_ep[1],
)
ts = nap.Ts(np.linspace(0, 10, 20))
out = tsdframe.interpolate(ts, ep=ep)
assert np.all(out.time_support == ep)

def test_as_dataframe(self, tsdframe):
assert isinstance(tsdframe.as_dataframe(), pd.DataFrame)

Expand Down Expand Up @@ -1589,6 +1647,34 @@ def test_count_dtype(self, dtype, expectation, ts):
)
class TestTsdTensor:

@pytest.mark.parametrize("delta_ep", [(1, -1), (-1, -1), (1, 1)])
def test_bin_average_time_support(self, delta_ep, tsdtensor):
ep = nap.IntervalSet(
tsdtensor.time_support.start[0] + delta_ep[0],
tsdtensor.time_support.end[0] + delta_ep[1],
)
out = tsdtensor.bin_average(0.1, ep=ep)
assert np.all(out.time_support == ep)

@pytest.mark.parametrize("delta_ep", [(1, -1), (-1, -1), (1, 1)])
def test_convolve_time_support(self, tsdtensor, delta_ep):
ep = nap.IntervalSet(
tsdtensor.time_support.start[0] + delta_ep[0],
tsdtensor.time_support.end[0] + delta_ep[1],
)
out = tsdtensor.convolve(np.ones(10), ep=ep)
assert np.all(out.time_support == ep)

@pytest.mark.parametrize("delta_ep", [(1, -1), (-1, -1), (1, 1)])
def test_interpolate_time_support(self, tsdtensor, delta_ep):
ep = nap.IntervalSet(
tsdtensor.time_support.start[0] + delta_ep[0],
tsdtensor.time_support.end[0] + delta_ep[1],
)
ts = nap.Ts(np.linspace(0, 10, 20))
out = tsdtensor.interpolate(ts, ep=ep)
assert np.all(out.time_support == ep)

def test_return_ndarray(self, tsdtensor):
np.testing.assert_array_equal(tsdtensor[0], tsdtensor.values[0])

Expand Down

0 comments on commit 440a9f4

Please sign in to comment.