pynapple-org / pynapple

PYthon Neural Analysis Package :pineapple:
https://pynapple-org.github.io/pynapple/
MIT License
243 stars 59 forks source link

Ts group getitem #263

Closed BalzaniEdoardo closed 2 months ago

BalzaniEdoardo commented 3 months ago

Content

This PR solves issue #243 And also addresses most of the issues raised in #246.

TsGroup Edits

__getattr__ method added.

Defined a __getattr__ that allows the following syntax,

meta_data_series = tsgroup.name  # get the column "name" of `self._metadata` DataFrame

Raises an error if the name is not in the metadata.

__setitem__ method modified.

TsGroup is now mutable, but allowing only the metadata to change after initialization. The __setitem__ allows only string as input, and enables,

self._metadata[key] = values

Raises error if the key is non-string.

__getitem__ method modified.

The __getitem__ of TsGroup logic was modified as follows,

  1. If one of the keys in self.keys() is passed, then the corresponding Ts is returned.
  2. If the string is in the self._metadata.columns (hence it is a str, hence it is not in self.keys()), then it returns self._metadata[key]
  3. If it is a bool ArrayLike of dim 1 it returns a TsGroup including the Ts corresponding to keys = np.where(bool_array)[0]
  4. If it is an intArrayLike of dim 1 it returns a TsGroup including the Ts corresponding to the array entries.
  5. Raises appropriate errors if none of the above conditions hold

Changes to interface_npz.py

Added keys to the set of keys that should not be appended to metadata.

coveralls commented 3 months ago

Pull Request Test Coverage Report for Build 8573132449

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
pynapple/core/ts_group.py 19 51 37.25%
<!-- Total: 19 51 37.25% -->
Totals Coverage Status
Change from base Build 8561902741: 0.2%
Covered Lines: 2298
Relevant Lines: 2635

💛 - Coveralls
alejoe91 commented 2 months ago

@BalzaniEdoardo seems to be working smoothly. Fixes #243

gviejo commented 2 months ago

Looks great. Last thing for TsGroup is to polish the __repr__ function. I can work on that.