Skip to content

Commit

Permalink
Merge pull request #289 from pynapple-org/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
gviejo authored May 22, 2024
2 parents 6cc56b3 + 1e82780 commit e207800
Show file tree
Hide file tree
Showing 10 changed files with 669 additions and 59 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches: [ main, dev ]

jobs:
lint:
Expand Down Expand Up @@ -40,9 +40,9 @@ jobs:
# - os: windows-latest
# python-version: 3.7
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -52,14 +52,12 @@ jobs:
- name: Test
run: |
coverage run --source=pynapple --branch -m pytest tests/
coverage report -m
coverage report -m
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pip install coveralls
coveralls --service=github
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
check:
if: always()
needs:
Expand Down
4 changes: 2 additions & 2 deletions pynapple/core/_core_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ def _threshold(time_array, data_array, starts, ends, thr, method):
if get_backend() == "jax":
from pynajax.jax_core_threshold import threshold

return threshold(time_array, data_array, starts, ends, thr, method)
return threshold(time_array, data_array[:], starts, ends, thr, method)
else:
return jitthreshold(time_array, data_array, starts, ends, thr, method)
return jitthreshold(time_array, data_array[:], starts, ends, thr, method)
11 changes: 8 additions & 3 deletions pynapple/core/_jitted_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,16 @@ def jitthreshold(time_array, data_array, starts, ends, thr, method="above"):
return (new_time_array, new_data_array, new_starts, new_ends)


@jit(nopython=True)
def jitbin_array(time_array, data_array, starts, ends, bin_size):
"""Slice first for compatibility with lazy loading."""
idx, countin = jitrestrict_with_count(time_array, starts, ends)
time_array = time_array[idx]
data_array = data_array[idx]
return _jitbin_array(
countin, time_array[idx], data_array[idx], starts, ends, bin_size
)


@jit(nopython=True)
def _jitbin_array(countin, time_array, data_array, starts, ends, bin_size):

m = starts.shape[0]
f = data_array.shape[1:]
Expand Down
54 changes: 38 additions & 16 deletions pynapple/core/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,18 @@ class BaseTsd(Base, NDArrayOperatorsMixin, abc.ABC):
Implement most of the shared functions across concrete classes `Tsd`, `TsdFrame`, `TsdTensor`
"""

def __init__(self, t, d, time_units="s", time_support=None):
def __init__(self, t, d, time_units="s", time_support=None, load_array=True):
super().__init__(t, time_units, time_support)

self.values = convert_to_array(d, "d")
if load_array:
self.values = convert_to_array(d, "d")
else:
if not is_array_like(d):
raise TypeError(
"Data should be array-like, i.e. be indexable, iterable and, have attributes "
"`shape`, `ndim` and, `dtype`)."
)
self.values = d

assert len(self.index) == len(
self.values
Expand Down Expand Up @@ -220,36 +228,38 @@ def __array_function__(self, func, types, args, kwargs):

def as_array(self):
"""
Return the data as a numpy.ndarray
Return the data.
Returns
-------
out: numpy.ndarray
out: array-like
_
"""
return self.values

def data(self):
"""
Return the data as a numpy.ndarray
Return the data.
Returns
-------
out: numpy.ndarray
out: array-like
_
"""
return self.values

def to_numpy(self):
"""
Return the data as a numpy.ndarray. Mostly useful for matplotlib plotting when calling `plot(tsd)`
Return the data as a numpy.ndarray.
Mostly useful for matplotlib plotting when calling `plot(tsd)`.
"""
return self.values
return np.asarray(self.values)

def copy(self):
"""Copy the data, index and time support"""
return self.__class__(
t=self.index.copy(), d=self.values.copy(), time_support=self.time_support
t=self.index.copy(), d=self.values[:].copy(), time_support=self.time_support
)

def value_from(self, data, ep=None):
Expand Down Expand Up @@ -662,7 +672,9 @@ class TsdTensor(BaseTsd):
The time support of the time series
"""

def __init__(self, t, d, time_units="s", time_support=None, **kwargs):
def __init__(
self, t, d, time_units="s", time_support=None, load_array=True, **kwargs
):
"""
TsdTensor initializer
Expand All @@ -677,7 +689,7 @@ def __init__(self, t, d, time_units="s", time_support=None, **kwargs):
time_support : IntervalSet, optional
The time support of the TsdFrame object
"""
super().__init__(t, d, time_units, time_support)
super().__init__(t, d, time_units, time_support, load_array)

assert (
self.values.ndim >= 3
Expand Down Expand Up @@ -831,7 +843,15 @@ class TsdFrame(BaseTsd):
The time support of the time series
"""

def __init__(self, t, d=None, time_units="s", time_support=None, columns=None):
def __init__(
self,
t,
d=None,
time_units="s",
time_support=None,
columns=None,
load_array=True,
):
"""
TsdFrame initializer
A pandas.DataFrame can be passed directly
Expand Down Expand Up @@ -859,7 +879,7 @@ def __init__(self, t, d=None, time_units="s", time_support=None, columns=None):
else:
assert d is not None, "Missing argument d when initializing TsdFrame"

super().__init__(t, d, time_units, time_support)
super().__init__(t, d, time_units, time_support, load_array)

assert self.values.ndim <= 2, "Data should be 1 or 2 dimensional."

Expand Down Expand Up @@ -1084,7 +1104,7 @@ def save(self, filename):
np.savez(
filename,
t=self.index.values,
d=self.values,
d=self.values[:],
start=self.time_support.start,
end=self.time_support.end,
columns=cols_name,
Expand All @@ -1108,7 +1128,9 @@ class Tsd(BaseTsd):
The time support of the time series
"""

def __init__(self, t, d=None, time_units="s", time_support=None, **kwargs):
def __init__(
self, t, d=None, time_units="s", time_support=None, load_array=True, **kwargs
):
"""
Tsd Initializer.
Expand All @@ -1129,7 +1151,7 @@ def __init__(self, t, d=None, time_units="s", time_support=None, **kwargs):
else:
assert d is not None, "Missing argument d when initializing Tsd"

super().__init__(t, d, time_units, time_support)
super().__init__(t, d, time_units, time_support, load_array)

assert self.values.ndim == 1, "Data should be 1 dimensional"

Expand Down
Loading

0 comments on commit e207800

Please sign in to comment.