Skip to content

Commit

Permalink
Merge pull request #239 from pynapple-org/dev
Browse files Browse the repository at this point in the history
Fixing IntervalSet loc
  • Loading branch information
gviejo authored Mar 3, 2024
2 parents b2f1775 + 0c4bf42 commit ea60357
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
6 changes: 6 additions & 0 deletions docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ In 2018, Francesco started neuroseries, a Python package built on Pandas. It was
In 2021, Guillaume and other trainees in Adrien's lab decided to fork from neuroseries and started *pynapple*. The core of pynapple is largely built upon neuroseries. Some of the original changes to TSToolbox made by Luke were included in this package, especially the *time_support* property of all ts/tsd objects.


0.6.1 (2024-03-03)
------------------

- Fixed pynapple `loc` method for new `IntervalSet`


0.6.0 (2024-03-02)
------------------

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.6.0"
__version__ = "0.6.1"
from .core import IntervalSet, Ts, Tsd, TsdFrame, TsdTensor, TsGroup, TsIndex, config
from .io import *
from .process import *
11 changes: 11 additions & 0 deletions pynapple/core/interval_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,17 @@ def get_intervals_center(self, alpha=0.5):
t = starts + (ends - starts) * alpha
return time_series.Ts(t=t, time_support=self)

def as_dataframe(self):
"""
Convert the `IntervalSet` object to a pandas.DataFrame object.
Returns
-------
out: pandas.DataFrame
_
"""
return pd.DataFrame(data=self.values, columns=["start", "end"])

def save(self, filename):
"""
Save IntervalSet object in npz format. The file will contain the starts and ends.
Expand Down
42 changes: 38 additions & 4 deletions pynapple/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
# @Author: Guillaume Viejo
# @Date: 2024-02-09 11:45:45
# @Last Modified by: gviejo
# @Last Modified time: 2024-02-21 21:27:04
# @Last Modified time: 2024-03-03 06:28:59

"""
Utility functions
"""

import warnings
from numbers import Number

import numpy as np
from numba import jit
Expand Down Expand Up @@ -279,22 +278,57 @@ def __getitem__(self, key):


class _IntervalSetSliceHelper:
"""
This class helps `IntervalSet` behaves like pandas.DataFrame for the `loc` function.
Attributes
----------
intervalset : `IntervalSet` to slice
"""

def __init__(self, intervalset):
"""Class for `loc` slicing function
Parameters
----------
intervalset : IntervalSet
"""
self.intervalset = intervalset

def __getitem__(self, key):
"""Getters for `IntervalSet.loc`. Mimics pandas.DataFrame.
Parameters
----------
key : int, list or tuple
Returns
-------
IntervalSet or Number or numpy.ndarray
Raises
------
IndexError
"""
if key in ["start", "end"]:
return self.intervalset[key]
elif isinstance(key, list):
return self.intervalset[key]
elif isinstance(key, Number):
elif isinstance(key, int):
return self.intervalset.values[key]
else:
if isinstance(key, tuple):
if len(key) == 2:
if key[1] not in ["start", "end"]:
raise IndexError
return self.intervalset[key[0]][key[1]]
out = self.intervalset[key[0]][key[1]]
if len(out) == 1:
return out[0]
else:
return out
else:
raise IndexError
else:
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.6.0"
version = "0.6.1"
description = "PYthon Neural Analysis Package Pour Laboratoires d’Excellence"
readme = "README.md"
authors = [{ name = "Guillaume Viejo", email = "[email protected]" }]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/pynapple-org/pynapple',
version='v0.6.0',
version='v0.6.1',
zip_safe=False,
long_description_content_type='text/markdown',
download_url='https://github.com/pynapple-org/pynapple/archive/refs/tags/v0.6.0.tar.gz'
Expand Down

0 comments on commit ea60357

Please sign in to comment.